chiark / gitweb /
@@@ wip
[mLib] / hash / t / unihash-testgen.py
index 2fe8982068436301d1a96f33b20eb2c87f6ee071..a8365aef297f0e72827ef569a6b13614c03b8b88 100644 (file)
@@ -3,6 +3,9 @@
 ###
 ### Generate test vectors for universal hashing.
 
+import sys as SYS
+if SYS.version_info >= (3,): xrange = range
+
 MOD = 0x104c11db7
 
 def gfmul(x, y):
@@ -17,17 +20,22 @@ def gfmul(x, y):
 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('')
+  print('k = 0x%08x' % k)
+  print('m = "%s"' % m)
+  print('h = 0x%08x' % h)
 
-print '''\
-### Test vectors for universal hashing
-###   [generated]
+print('''\
+;;; -*-conf-*- Test vectors for universal hashing
+;;;   [generated]
 
-hash {'''
+[unihash]''')
 
 for k, m in [(0x00000000, 'anything you like'),
              (0x12345678, 'an exaple test string'),
              (0xb8a171f0, 'The quick brown fox jumps over the lazy dog.'),
+             (0xcc825ed5, 'Jackdaws love my big sphinx of quartz.'),
+             (0x16e98e46, 'Waltz, bad nymph, for quick jigs vex!'),
              (0x2940521b, 'A man, a plan, a canal: Panama!')]:
   hashtest(k, m)
 
@@ -35,5 +43,3 @@ k, m = 0x94b22a73, 0xbb7b1fef
 for i in xrange(48):
   hashtest(k, "If we don't succeed, we run the risk of failure.")
   k = gfmul(k, m)
-
-print '}'