c1 = "1010110010011110011111101110011001101100111010001111011101101011101000110010011000000101001110111010010111100100111101001010000011000001010001001001010000000010101001000011100100010011011011011011010111010011000101010111111110010011010111001001010101110001111101010000001011110100000000010010111001111010110000001101010010110101100010011111111011101101001011111001101111101111000100100001000111101111011011001011110011000100011111100001000101111000011101110101110010010100010111101111110011011011001101110111011101100110010100010001100011001010100110001000111100011011001000010101100001110011000000001110001011101111010100101110101000100100010111011000001111001110000011111111111110010111111000011011001010010011100011100001011001101110110001011101011101111110100001111011011000110001011111111101110110101101101001011110110010111101000111011001111" c2 = "1011110110100110000001101000010111001000110010000110110001101001111101010000101000110100111010000010011001100100111001101010001001010001000011011001010100001100111011010011111100100101000001001001011001110010010100101011111010001110010010101111110001100010100001110000110001111111001000100001001010100011100100001101010101111000100001111101111110111001000101111111101011001010000100100000001011001001010000101001110101110100001111100001011101100100011000110111110001000100010111110110111010010010011101011111111001011011001010010110100100011001010110110001001000100011011001110111010010010010110100110100000111100001111101111010011000100100110011111011001010101000100000011111010010110111001100011100001111100100110010010001111010111011110110001000111101010110101001110111001110111010011111111010100111000100111001011000111101111101100111011001111" words = ['was', 'for', 'on', 'are', 'as', 'with', 'his', 'they', 'I', 'at', 'be', 'this', 'have', 'from', 'or', 'one', 'had', 'by', 'word', 'but', 'not', 'what', 'all', 'were', 'we', 'when', 'your', 'can', 'said', 'there', 'use', 'an', 'each', 'which', 'she', 'do', 'how', 'their', 'if', 'will', 'up', 'other', 'about', 'out', 'many', 'then', 'them', 'these', 'so', 'some', 'her', 'would', 'make', 'like', 'him', 'into', 'time', 'has', 'look', 'two', 'more', 'write', 'go', 'see', 'number', 'no', 'way', 'could', 'people', 'my', 'than', 'first', 'water', 'been', 'call', 'who', 'oil', 'its', 'now', 'find', 'long', 'down', 'day', 'did', 'get', 'come', 'made', 'may', 'part', 'state'] def xor(char1, char2): if char1 == '0': int1 = 0 else: int1 = 1 if char2 == '0': int2 = 0 else: int2 = 1 return int1 ^ int2 def stringtoBinaryString(string, bits): s = "" for p in range(0, len(string)): c = bin(ord(string[p])) c = c[2:len(c)] while len(c) < bits: c = "0" + c s += c return s def xorStrings(string1, string2): length = len(string1) pos = 0 xorArray = [None]*length while pos < length: xorArray[pos] = xor(string1[pos], string2[pos]) pos = pos + 1 return xorArray def bitArrayToBitString(bitArray): s = "" for p in range(0, len(bitArray)): if bitArray[p] == 0: s += "0" else: s += "1" return s def arraytoString(array, bits): s = "" c = 0 for p in range(0, len(array)): c = c + (array[p] << (bits - (p % bits) - 1)) if(p % 7 == 6): if c == 13: s += "!!!CARRIAGE RETURN!!!!" else: s += chr(c) c = 0 return s def guessKeyPart(guessWord, string1, string2, bits): guessString = stringtoBinaryString(guessWord, bits) for p in range(0, len(string1) - len(guessString), bits): guessedKey = xorStrings(guessString, string1[p:p+len(guessString)]) guessedKeyString = bitArrayToBitString(guessedKey) senseString = xorStrings(guessedKeyString, string2[p:p+len(guessString)]) print (str(p / bits) + " " + arraytoString(senseString, bits)) guessKeyPart("I visualize a time when we will be to robots what dogs are to humans, and I'm rooting for the machines. (Claude Shannon)", c1, c2, 7)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question