Skip to content

Commit

Permalink
Added docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Færevaag committed Jun 23, 2013
1 parent 445963d commit ba97043
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions project2/RainbowAttack.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
SERIAL_NO = 0123456

#s = random.getrandbits(BIT_SIZE)
s = int("0x57c09f4", 16)
s = int('0xcf496ab', 16)
u = int("0xdaffeda", 16)


Expand All @@ -43,15 +43,13 @@ def cstring(msg, color):
def f(s, i=0):
"""Lowest 28 bits of (MD5(s||u) % i)"""
digest = md5.new(str(s) + str(u)).hexdigest()[:BIT_SIZE/4]
if i is 0: return int(digest, 16)
result = (int(digest, 16) + i) % 2**BIT_SIZE
return result


def read_table():
"""Read Rainbow Table from csv file"""
dict = {}

with open(TABLE_NAME, 'rb') as csvfile:
table = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in table:
Expand All @@ -61,18 +59,22 @@ def read_table():


def find_key(table, r):
"""Search for matching respons in Rainbow-table"""
succ = [f(r)]
for i in xrange(1, CHAIN_LEN - 1):
succ.append(f(succ[i-1], i))

for key, value in table.iteritems():
if value in succ:
print "\tKey: 0x%x Value: 0x%x" % (key, value)
for i in xrange(1, CHAIN_LEN - 1):
ss = f(key, i)
rs = f(ss)
print "\tCollition: 0x%x -> 0x%x" % (key, value)
ss = key
for i in xrange(0, CHAIN_LEN - 1):
rs = f(ss, i)
# print "0x%x" % rs,
if rs == r:
print "\tWOW: 0x%x" % ss
return ss
else:
ss = rs

return -1

Expand All @@ -97,7 +99,7 @@ def main():

print "\tActual key: 0x%x" % s

exit(1 if key is -1 else 0)
return 1 if key is -1 else 0


if __name__ == '__main__':
Expand Down

0 comments on commit ba97043

Please sign in to comment.