incubator-tashi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Shaye-Wen Wang" <msw...@andrew.cmu.edu>
Subject Patch
Date Mon, 06 Jul 2009 20:38:02 GMT
Here is a patch for the maui checksum algorithm implemented without seeing
the actual code.

Index: src/utils/pseudoDes.py
===================================================================
--- src/utils/pseudoDes.py  (revision 0)
+++ src/utils/pseudoDes.py  (revision 0)
@@ -0,0 +1,57 @@
+#! /usr/bin/env python
+values = { 1:(0xcba4e531, 0x12be4590),
+           2:(0x537158eb, 0xab54ce58),
+           3:(0x145cdc3c, 0x6954c7a6),
+           4:(0x0d3fdeb2, 0x15a2ca46)}
+
+def crc(short, char):
+   short = short & 0xffff
+   char = char & 0xff
+   value = short ^ (char << 8)
+   for i in range(0, 8):
+       if value & 0x8000:
+           value = (value << 1) ^ 4129
+       else:
+           value = value << 1
+   return value & 0xffff
+
+def pseudoDes(in1, in2):
+   for i in range(1, 5):
+       in1 = in1 & 0xffffffff
+       in2 = in2 & 0xffffffff
+       (value1, value2) = values[i]
+
+       out1 = in2
+       tmp2 = in2 ^ value1
+       tmp1 = ((tmp2 & 0xffff)*(tmp2 & 0xffff)) + ((~((tmp2 >> 16)*(tmp2
>> 16))) & 0xffffffff)
+       tmp1 = tmp1 & 0xffffffff
+       out2 = in1 ^ ((((tmp1 >> 16) | ((tmp1 & 0xffff) << 16)) ^ value2)
+ ((tmp2 & 0xffff) * (tmp2 >> 16)))
+
+       in1, in2 = out1, out2
+   out1 = 0xffffffff & out1
+   out2 = 0xffffffff & out2
+   return out1, out2
+
+def generateKey(msg, key):
+   crcValue = 0
+   for char in msg:
+       crcValue = crc(crcValue, ord(char))
+   left, right = pseudoDes(crcValue, key)
+   return (left << 32) | right
+
+if __name__ == '__main__':
+   msg = 'I am not a crook'
+   key = 35005211
+   print hex(generateKey(msg, key))
+   msg = 'Hello World!'
+   key = 521595368
+   print hex(generateKey(msg, key))
+   msg = 'pseudo des'
+   key = 294702567
+   print hex(generateKey(msg, key))
+   msg = 'copyright infringement'
+   key = 1726956429
+   print hex(generateKey(msg, key))
+   msg = 'whiteboard cowboy'
+   key = 336465782
+   print hex(generateKey(msg, key))



Mime
View raw message