def s1c3(): bestscore = 0 beststring = "" for key in string.ascii_letters: #iterate key possibilities result = "" for j in range(0,length): part = cipher[j] #get a byte from cipher xorpart = (part ^ ord(key))# xor int form result = result + chr(xorpart) # decide the likleyhood the string is deciphered x = getStringScore(result) if(x >= bestscore): bestscore = x beststring = result print(beststring) return 0
def runkeys(ln): global bestscore global bestline #iterate all possible keys for k in string.printable: result = "" key = ord(k) #letter to int # apply xor across the string for j in range(0,len(ln)): part = (key ^ ln[j]) #xor byte result = result + chr(part) #concat the bytes #determine the greatest possible score for the line x = getStringScore(result) if(x > bestscore): bestscore = x bestline = result return 0