1993-12-14 15:54:01 +00:00
|
|
|
# Testing md5 module
|
|
|
|
|
|
|
|
import string
|
|
|
|
from md5 import md5
|
|
|
|
|
|
|
|
def hexstr(s):
|
2000-10-23 17:22:08 +00:00
|
|
|
h = string.hexdigits
|
|
|
|
r = ''
|
|
|
|
for c in s:
|
|
|
|
i = ord(c)
|
|
|
|
r = r + h[(i >> 4) & 0xF] + h[i & 0xF]
|
|
|
|
return r
|
1993-12-14 15:54:01 +00:00
|
|
|
|
|
|
|
def md5test(s):
|
2000-10-23 17:22:08 +00:00
|
|
|
return 'MD5 ("' + s + '") = ' + hexstr(md5(s).digest())
|
1993-12-14 15:54:01 +00:00
|
|
|
|
|
|
|
print 'MD5 test suite:'
|
|
|
|
print md5test('')
|
|
|
|
print md5test('a')
|
|
|
|
print md5test('abc')
|
|
|
|
print md5test('message digest')
|
|
|
|
print md5test('abcdefghijklmnopqrstuvwxyz')
|
|
|
|
print md5test('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
|
|
|
|
print md5test('12345678901234567890123456789012345678901234567890123456789012345678901234567890')
|
2000-08-15 06:01:36 +00:00
|
|
|
|
|
|
|
# hexdigest is new with Python 2.0
|
|
|
|
m = md5('testing the hexdigest method')
|
|
|
|
h = m.hexdigest()
|
2000-12-12 23:11:42 +00:00
|
|
|
if hexstr(m.digest()) != h:
|
2000-10-23 17:22:08 +00:00
|
|
|
print 'hexdigest() failed'
|