chiark
/
gitweb
/
~mdw
/
mLib
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
*/t/*.py: Fix the various testing scripts for Python 3 compatibility.
[mLib]
/
hash
/
t
/
unihash-testgen.py
diff --git
a/hash/t/unihash-testgen.py
b/hash/t/unihash-testgen.py
index 2fe8982068436301d1a96f33b20eb2c87f6ee071..1fde21f947ada40c99840dd0bf2d7fc8518f78ee 100644
(file)
--- a/
hash/t/unihash-testgen.py
+++ b/
hash/t/unihash-testgen.py
@@
-3,6
+3,9
@@
###
### Generate test vectors for universal hashing.
###
### Generate test vectors for universal hashing.
+import sys as SYS
+if SYS.version_info >= (3,): xrange = range
+
MOD = 0x104c11db7
def gfmul(x, y):
MOD = 0x104c11db7
def gfmul(x, y):
@@
-17,13
+20,13
@@
def gfmul(x, y):
def hashtest(k, m):
h = k
for ch in m: h = gfmul(h ^ ord(ch), k)
def hashtest(k, m):
h = k
for ch in m: h = gfmul(h ^ ord(ch), k)
- print
' 0x%08x "%s" 0x%08x;' % (k, m, h
)
+ print
(' 0x%08x "%s" 0x%08x;' % (k, m, h)
)
-print
'''\
+print
(
'''\
### Test vectors for universal hashing
### [generated]
### Test vectors for universal hashing
### [generated]
-hash {'''
+hash {'''
)
for k, m in [(0x00000000, 'anything you like'),
(0x12345678, 'an exaple test string'),
for k, m in [(0x00000000, 'anything you like'),
(0x12345678, 'an exaple test string'),
@@
-36,4
+39,4
@@
for i in xrange(48):
hashtest(k, "If we don't succeed, we run the risk of failure.")
k = gfmul(k, m)
hashtest(k, "If we don't succeed, we run the risk of failure.")
k = gfmul(k, m)
-print
'}'
+print
('}')