Skip to content

Commit

Permalink
Init TableGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Færevaag committed Jun 23, 2013
1 parent c719e4c commit 24fa79e
Show file tree
Hide file tree
Showing 3 changed files with 262,218 additions and 261,996 deletions.
2 changes: 1 addition & 1 deletion project2/RainbowAttack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

BIT_SIZE = 28
CHAIN_LEN = 2**10
TABLE_NAME = "rainbowproject2_long.csv"
TABLE_NAME = 'table.csv' #"rainbowproject2_long.csv"
SERIAL_NO = 0123456

s = random.getrandbits(BIT_SIZE)
Expand Down
74 changes: 74 additions & 0 deletions project2/TableGenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#
# Project 2
#
# 01435 Practiacal Cryptanalysis
# Technical University of Denmark

# Markus Faerevaag (s123692@student.dtu.dk)
# Christian Mathias Rohde Kiaer (s123812@student.dtu.dk)
# Jonathan Becktor (s123094@student.dtu.dk)
#

import os, md5, random, csv, time

BIT_SIZE = 28
NUM_CHAINS = 2**18
CHAIN_LEN = 2**10
TABLE_NAME = "table.csv"
LOG_FREQ = 5000

u = int("0xdaffeda", 16)


def md5_redux(s, i=0):
"""Lowest 28 bits of (MD5(s||u) % i)"""
digest = md5.new(str(s) + str(u)).hexdigest()[:BIT_SIZE/4]
result = (int(digest, 16) + i) % 2**BIT_SIZE
return result


def generate_table():
"""Generates a rainbow table"""
dict = {}
order = []
counter = 0

for i in xrange(0, NUM_CHAINS - 1):
red = hex(random.getrandbits(20))[:-1]
red_start_point = red

for x in xrange(0, CHAIN_LEN - 1):
red = md5_redux(red, x)

red_end_point = red

if counter % LOG_FREQ == 0:
print "Took i calls: %d keys: %d" % (i, counter)

order.append(red_start_point)
dict[red_start_point] = red_end_point
counter += 1

write_to_csv(dict, order)


def write_to_csv(dict, order):
"""Writes the rainbow table to a .csv file"""
w = csv.writer(open(TABLE_NAME, 'w'))
for key in order:
value = dict[key]
w.writerow([key, hex(value)])


def main():
start = time.clock()

generate_table()

end = time.clock()
print "Took: ", (end - start), " s"


if __name__ == '__main__':
main()

Loading

0 comments on commit 24fa79e

Please sign in to comment.