# -*- coding:utf-8 -*- # Author: Jason Ye # Time: 2016/03/15 import sys defreadInCypherText(fileName): """ Read in cypher texts """ cypherText =  with open(fileName) as f: for line in f: cypherText.append(line) return cypherText
definitialKey(cypherText): maxLen = 0 key =  for text in cypherText: maxLen = max(maxLen, (len(text)-1)/2) for i in range(maxLen): key.append("*") return key
defprintKey(key): print"[Key]" + str(len(key)/2) for index, key in enumerate(key): if(key == "*"): sys.stdout.write("** ") else: sys.stdout.write(hex(int(key)).replace("0x",'')+" ") if((index+1)%16==0): print'' print''
defdecrypt(key, ct): pt = '' lenOfCT = len(ct) - 1 for ptr in range(0,lenOfCT,2): c = ct[ptr] + ct[ptr+1] c = int(c,16) if(key[ptr/2] != "*"): sys.stdout.write(chr(c^int(key[ptr/2]))) else: sys.stdout.write("*") print'' sys.stdout.flush()
defgetKey(ct, pos, p): a = int(ct[pos*2] + ct[pos*2+1],16) k = a ^ ord(p) return k
#Find K(space) for i in cypherText: lenOfText = len(i) - 1 print"[Length] " + str(cypherText.index(i)) + ": " +str(lenOfText/2) for ptr in range(0,lenOfText,2): # sys.stdout.write(i[ptr]+i[ptr+1]+" ") isSpace = True a = int(i[ptr] + i[ptr+1],16) for j in cypherText: jLen = len(j) if(i!=j and ptr+1 < jLen): b = int(j[ptr] + j[ptr+1],16) c = a ^ b if(not str.isalpha(chr(c))): isSpace = False elif(ptr+1>jLen): isSpace = False if(not isSpace): # sys.stdout.write(i[ptr]+i[ptr+1]+" ") pass else: # sys.stdout.write("__ ") key[ptr/2] = str(a ^ 0x20) if((ptr+2) % 32 == 0): print'' print''
printKey(key) # Print current plaintext deciphered for i in range(190): sys.stdout.write(str(i%10)) print'' for ct in cypherText: decrypt(key, ct) print"\n" sys.stdout.flush() # Guess with open("log.txt",'w') as log: # Log down the decryption to file in case some guesses are not right try: while(True): try: # Preventing invalid input line, pos, p = raw_input().split() except: print"Invalid input! Input again" sys.stdout.flush() continue if(p == "*"): # Undo the guess key[int(pos)] = "*" print"Key revised\n\n" continue elif(p == "done"): break sys.stdout.write(line + "line: " + pos+" "+p +'\n') log.write(line + " " + pos + " " + p + "\n") key[int(pos)] = getKey(cypherText[int(line)], int(pos), p) # Print the header of number for i in range(190): sys.stdout.write(str(i%10)) print'' # Print current plain text deciphered for ct in cypherText: decrypt(key, ct) print"\n\n"
We can factor the number 15 with quantum computers. We can also factor the number 15 with a dog trained to bark three times - Robert Harley Euler would probably enjoy that now his theorem becomes a corner stone of crypto - Annonymous on Euler's theorem The nice thing about Keeyloq is now we cryptographers can drive a lot of fancy cars - Dan Boneh The ciphertext produced by a weak encryption algorithm looks as good as ciphertext produced by a strong encryption algorithm - Philip Zimmermann You don't want to buy a set of car keys from a guy who specializes in stealing cars - Marc Rotenberg commenting on Clipper There are two types of cryptography - that which will keep secrets safe from your little sister, and that which will keep secrets safe from your government - Bruce*Schn**** There are two types of cyptography: one that allows the Government to use brute force to break the code, and one that requires the Government to use brute force to*brea****************** We can see the point where the chip is unhappy if a wrong bit is sent and consumes more power from the environment - Adi Shamir A (private-key) encryption scheme states 3 algorithms, namely a procedure for generating keys, a procedure for encrypting, and a procedure for decrypting. The Concise OxfordDictionary (2006) de铿乶es crypto as the art of writing o r solving codes.