New topic: 

MD5 value (hex)

<http://forums.realsoftware.com/viewtopic.php?t=28850>

       Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic         Author  
Message       spacewalker           Post subject: MD5 value (hex)Posted: Sun 
Jul 05, 2009 12:21 pm                        
Joined: Thu Nov 08, 2007 4:59 am
Posts: 253
Location: Germany              Hello,

I have a problem with calculating the MD5 value for a string "99ce7517".

I understood that the RB MD5 function returns the binary value of MD5.
But I would need a hex representation.

I know that the correct MD5 value should be :
md5("99ce7517") = "01f7b2cd5b861399d2cba2d52a27ed4a"

I get this correct value when I calculate the MD5 for example on this site:
http://www.adamek.biz/md5-generator.php
(Input:  99ce7517  Result: 01f7b2cd5b861399d2cba2d52a27ed4a)


I have found 2 articles that claim to convert a binary MD5 to hex - but they 
didn't work for me:
For example: viewtopic.php?f=10&t=26253  :

Code:ConvertToHex ( md5("99ce7517") ) = "68317C1D91567F633E4D88B9BE66610F" 
//should be:  "01f7b2cd5b861399d2cba2d52a27ed4a"

Private Function ConvertToHex(Source As String) As String
  Dim SrcMB As MemoryBlock
  SrcMB=New MemoryBlock(Source.LenB)
  SrcMB.StringValue(0,SrcMB.Size)=Source
  
  Dim ReturnValue As String
  Dim OneBitHex As String
  For i As Integer=0 To SrcMB.Size-1
  OneBitHex=Hex(SrcMB.Byte(i))
  If i<>0 Then
  If OneBitHex.Len=1 Then OneBitHex="0" + OneBitHex
  End If
  ReturnValue=ReturnValue+OneBitHex
  Next
  
  Return ReturnValue

Thank you     
_________________
  
                            Top               DaveS           Post subject: Re: 
MD5 value (hex)Posted: Sun Jul 05, 2009 1:11 pm                               
Joined: Sun Aug 05, 2007 10:46 am
Posts: 1235
Location: San Diego, CA              Code:
FUNCTION MD5_2_HEX(s as string) as string
  const strHex="0123456789ABCDEF"
  dim t as string
  dim i as integer
  dim x as integer
  s=md5(s)
  for i=1 to len(s)
  x=(ascb(mid(s,i,1)) and &HF0)/16
  t=t+mid(strHex,x+1,1)
  x=(ascb(mid(s,i,1)) and &H0f)
  t=t+mid(strHex,x+1,1)
  next i
  return t
END FUNCTION




msgbox md5_2_hex("99ce7517")


Tested... and returns the result you indicated     
_________________
Dave Sisemore
MacPro, RB2008r3.1  
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to