md5 object problem
I can't get the MD5 object to work, there are no samples or notes on how to use it, so this is what I am trying (looks correct anyway):
and what I get in nstr is: one line down, and 11 or so in: 8vA_ Ұ
not, the 16 byte string I was expecting.
I've gotten other weird results with other input strings. What am I doing wrong?
CON
MAX_STR_LEN = 25
OBJ
MD5 : "MD5"
VAR
byte nd[noparse][[/noparse]MAX_STR_LEN]
byte nstr[noparse][[/noparse]MAX_STR_LEN]
PUB do_hash
bytemove(@nd, string("abcdefghijklmn 1234567890"), MAX_STR_LEN)
MD5.hash(@nd, MAX_STR_LEN, @nstr)
and what I get in nstr is: one line down, and 11 or so in: 8vA_ Ұ
not, the 16 byte string I was expecting.
I've gotten other weird results with other input strings. What am I doing wrong?

Comments
VAR byte nd[noparse][[/noparse]MAX_STR_LEN] byte nstr[noparse][[/noparse]MD5#HASH_LENGTH] PUB do_hash | str str := string("abcdefghijklmn 1234567890") ' Save the address of the constant string bytemove(@nd,str,strsize(str)) ' Use the actual length of the string MD5.hash(@nd,strsize(str),@nstr) ' Again use the actual lengthThe do_hash call will create a 16 byte hash in nstr. Note that this hash is not in displayable form.
It consists of 16 bytes with values from 0 to 255. You have to display the bytes in hexadecimal or
decimal form to make any sense of them. There are hexadecimal display routines in most of the
display objects (serial.hex(<value>,<#digits>) for example).
REPEAT MD5#HASH_LENGTH DEBUG.hex(nstr[noparse][[/noparse]i++], 2)It seems to return something legit, but it doesn't match the MD5 I know works (on PSPad and PHP).
Prop MD5: B1963AC8BCB9905FE513D45A98633210
PSPad MD5: 63d7f5da7e0c01fec14ca1cf9016541f
any ideas?
Post Edited (Bobb Fwed) : 10/6/2008 5:49:46 PM GMT
Something doesn't seem right.
Post Edited (Bobb Fwed) : 10/6/2008 5:51:26 PM GMT
I've done it both ways, and see the bytemove is required to get the correct hash, just don't understand why.
Can anyone elaborte?
Thanks,
Scott
CON _CLKMODE = XTAL1 _XINFREQ = 5_000_000 ' 5MHz Crystal OBJ DEBUG : "FullDuplexSerial" MD5 : "MD5" VAR byte nstr[noparse][[/noparse]MD5#HASH_LENGTH] PUB Main DEBUG.start(31, 30, 0, 57600) waitcnt(clkfreq + cnt) DEBUG.tx($0D) do_hash PUB do_hash | str, i str := string("abcdefghijklmn 1234567890") MD5.hash(str, strsize(str), @nstr) i~ REPEAT MD5#HASH_LENGTH DEBUG.hex(nstr[noparse][[/noparse]i++], 2) DEBUG.tx($D)But this is probably what should be used.
CON _CLKMODE = XTAL1 _XINFREQ = 5_000_000 ' 5MHz Crystal MAX_STR_LEN = 64 OBJ DEBUG : "FullDuplexSerial" MD5 : "MD5" VAR byte nd[noparse][[/noparse]MAX_STR_LEN] byte nstr[noparse][[/noparse]MD5#HASH_LENGTH] PUB Main DEBUG.start(31, 30, 0, 57600) waitcnt(clkfreq + cnt) DEBUG.tx($0D) do_hash PUB do_hash | str, i str := string("abcdefghijklmn 1234567890") bytemove(@nd, str, strsize(str)) MD5.hash(@nd, strsize(str), @nstr) i~ REPEAT MD5#HASH_LENGTH DEBUG.hex(nstr[noparse][[/noparse]i++], 2) DEBUG.tx($D)Both output the correct value: "63D7F5DA7E0C01FEC14CA1CF9016541F"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!