\r
function md5tostr(const md5:tmd5):ansistring;\r
\r
+function md5selftest:boolean;\r
+\r
implementation\r
\r
function inttohex(val,bits:integer):ansistring;\r
b := state.msglen and 63;\r
\r
inc(state.msglen,len);\r
- while (state.msglen > $20000000) do begin\r
+ while (state.msglen >= $20000000) do begin\r
dec(state.msglen,$20000000);\r
inc(state.msglenhi);\r
end;\r
md5tostr := s;\r
end;\r
\r
+function md5selftest;\r
+const\r
+ teststring:ansistring='The quick brown fox jumps over the lazy dog';\r
+ testresult:array[0..15] of byte=($9e,$10,$7d,$9d,$37,$2b,$b6,$82,$6b,$d8,$1d,$35,$42,$a4,$19,$d6);\r
+var\r
+ h:tmd5;\r
+ a:integer;\r
+begin\r
+ getmd5(teststring[1],length(teststring),h);\r
+ result := true;\r
+ for a := 0 to 15 do if h[a] <> ord(testresult[a]) then result := false;\r
+end;\r
+\r
+\r
end.\r