def key(self, text, enc): output = "" with open(text, "r+b") as f: with open(enc, "r+b") as f1: while 1: read_data = f.read(1) read_enc = f1.read(1) if not read_data: break output += chr((ord(read_enc) - ord(read_data) + 256) % 256) r = re.compile(r"(.+?)\1+") print r.findall(output) vigenere = Vigenere() test = vigenere.decipher(enc, r.findall(output)[0])
def breakOpenDic(self,enc): key = "" words = 0 word_list = [] for a in brown.words(fileids=['cc17','ca16']): word_list.append(str(a)) for a in word_list: vigenere = Vigenere() file = vigenere.decipher(enc,a) n = self.compare(file) if n > words: key = a words = n print key
def breakOpen(self,enc): lower_a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] upper_a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] all = [] all = lower_a + upper_a + num words = 0 key = "" for r in range(1, 5): for s in itertools.product(all, repeat = r): vigenere = Vigenere() file = vigenere.decipher(enc,''.join(s)) n = self.compare(file) if n > words: key = ''.join(s) words = n print key
def test_short(): vig_short = Vigenere(alphabet, short) ciphered = vig_short.cipher(message) assert ciphered == "TSMWTSNFBEFLPJWUENG" assert vig_short.decipher(ciphered) == message
def test_extra_points(): vig_random = Vigenere(alphabet) ciphered = vig_random.cipher(message) assert vig_random.decipher(ciphered) == message assert len(vig_random.password) >= 4
def test_semi_long(): vig_semi_long = Vigenere(alphabet, semi_long) ciphered = vig_semi_long.cipher(message) assert ciphered == "IFWYVWWUXMQFTXIORHF" assert vig_semi_long.decipher(ciphered) == message
def test_long(): vig_long = Vigenere(alphabet, long) ciphered = vig_long.cipher(message) assert ciphered == "IFWYVWWUOEYWNCIGBPI" assert vig_long.decipher(ciphered) == message
transposition = Transposition() if option == "c": transposition.cipher(from_file,int(key)) elif option == "d": transposition.decipher(from_file,int(key)) else: print "Option doesn't exist." elif algorithm == "v": vigenere = Vigenere() if option == "c": vigenere.cipher(from_file,key) elif option == "d": vigenere.decipher(from_file,key) else: print "Option doesn't exist." elif algorithm == "s": substitution = Substitution() if option == "c": substitution.cipher(from_file,key) elif option == "d": substitution.decipher(from_file,key) else: print "Option doesn't exist." else: print "Algorithm doesn't exist."