Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f6b4a5

Browse files
committed
Merged revisions 82351 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r82351 | brian.curtin | 2010-06-28 19:14:28 -0500 (Mon, 28 Jun 2010) | 3 lines Update md5driver.py for 3.x. Changed an import, replaced md5.new() with md5(), and added an encode where needed. ........
1 parent 26eb9d0 commit 5f6b4a5

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

Demo/md5test/md5driver.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
from hashlib import md5
12
import string
2-
import md5
33
from sys import argv
44

55
def MDPrint(str):
66
outstr = ''
7-
for i in str:
8-
o = ord(i)
7+
for o in str:
98
outstr = (outstr
109
+ string.hexdigits[(o >> 4) & 0xF]
1110
+ string.hexdigits[o & 0xF])
@@ -42,7 +41,7 @@ def MDTimeTrial():
4241
print('MD5 time trial. Processing', TEST_BYTES, 'characters...')
4342
t1 = time()
4443

45-
mdContext = md5.new()
44+
mdContext = md5()
4645

4746
for i in range(TEST_BLOCKS):
4847
mdContext.update(data)
@@ -57,13 +56,13 @@ def MDTimeTrial():
5756

5857

5958
def MDString(str):
60-
MDPrint(md5.new(str).digest())
59+
MDPrint(md5(str.encode("utf-8")).digest())
6160
print('"' + str + '"')
6261

6362

6463
def MDFile(filename):
6564
f = open(filename, 'rb')
66-
mdContext = md5.new()
65+
mdContext = md5()
6766

6867
while 1:
6968
data = f.read(1024)
@@ -78,7 +77,7 @@ def MDFile(filename):
7877
import sys
7978

8079
def MDFilter():
81-
mdContext = md5.new()
80+
mdContext = md5()
8281

8382
while 1:
8483
data = sys.stdin.read(16)

0 commit comments

Comments
 (0)