Skip to content

Commit

Permalink
Improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Færevaag committed Jun 22, 2013
1 parent dfe5257 commit 6b2255c
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions project3/breaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

TIMEINT_START = 1245646800
TIMEINT_END = 1246251599
CIPHERFILE = "ciphertext_sheet3.txt"

a = 69.069
c = 5
Expand All @@ -22,16 +23,42 @@ def update(s):
return (a * s + c) % m


def main():
# Init s as s_0
s = TIMEINT_START

def init_key(s):
key = []
for i in xrange(0, 15):
s = update(s)
key.append(float.hex(s)[-6:-4])
key.append(int(float.hex(s)[-6:-4], 16))

return key


def load_cipher():
f = open(CIPHERFILE, 'r')
ciphertext = []
for line in f:
for c in line:
ciphertext.append(c)

return ciphertext


def encrypt(c, key, i):
# return ord(c)
return int(ord(c)) ^ key[i % 16]


def main():
# Init s as s_0
key = init_key(TIMEINT_START)

# print key

ciphertext = load_cipher()

# print ciphertext

print key
for i in xrange(0, 10):
print encrypt(ciphertext[i], key[i], i)


if __name__ == '__main__':
Expand Down

0 comments on commit 6b2255c

Please sign in to comment.