def test_decrypt(self): cipher = Caesar() cipher_text = "zidryxsckqoxobkvzebzycosxdobzbodonrsqrvofovzbyqbkwwsxqvkxqekqo" open_text = cipher.decrypt(cipher_text, "k") expected = "pythonisageneralpurposeinterpretedhighlevelprogramminglanguage" self.assertEqual(open_text, expected) self.assertEqual(cipher.decrypt("", "a"), "")
def test_cs_crack(self): cipher = Caesar() cracker = CaesarBruteForce() open_text = normalize_text("Ja, Syn Poklopu, rozzuren do silenstvi, vodarnu srovnam se zemi, jmenem mistru kanvodstvi. Ja, matku vlastni, vsak kdo vi zda, prokouknutou mel, nikoliv jak pribuzni. ") key = "d" cipher_text = cipher.encrypt(open_text, key) langmodel = LangModel(get_lang_path('cs')) cracked_key = cracker.crack(cipher_text, LanguageStats(langmodel)) self.assertEqual(cracked_key, key)
def test_cs_crack(self): cipher = Caesar() cracker = TriangleAttack() open_text = normalize_text( "Ja, Syn Poklopu, rozzuren do silenstvi, vodarnu srovnam se zemi, jmenem mistru kanvodstvi. Ja, matku vlastni, vsak kdo vi zda, prokouknutou mel, nikoliv jak pribuzni. Tak jako davno pred casem jsme svatou chatru topily, stejny konec pripravime podvodnikum z vodarny. Nelze verit nikomu, kdo ma tlamu plnou cistoty. Vsechny tyhle bestie ceka voda ze stoky." ) key = "q" cipher_text = cipher.encrypt(open_text, key) langmodel = LangModel(get_lang_path('cs')) cracked_key = cracker.crack(cipher_text, LanguageStats(langmodel)) self.assertEqual(cracked_key, key)
def test_cs_crack(self): cipher = Caesar() cracker = TriangleAttack() open_text = normalize_text( "Ja, Syn Poklopu, rozzuren do silenstvi, vodarnu srovnam se zemi, jmenem mistru kanvodstvi. Ja, matku vlastni, vsak kdo vi zda, prokouknutou mel, nikoliv jak pribuzni. Tak jako davno pred casem jsme svatou chatru topily, stejny konec pripravime podvodnikum z vodarny. Nelze verit nikomu, kdo ma tlamu plnou cistoty. Vsechny tyhle bestie ceka voda ze stoky." ) key = "q" cipher_text = cipher.encrypt(open_text, key) langmodel = LangModel(get_lang_path("cs")) cracked_key = cracker.crack(cipher_text, LanguageStats(langmodel)) self.assertEqual(cracked_key, key)
def test_encrypt(self): cipher = Caesar() open_text = normalize_text("Python is a general-purpose, interpreted high-level programming language") cipher_text = cipher.encrypt(open_text, "a") self.assertEqual(cipher_text, open_text) cipher_text = cipher.encrypt(open_text, "k") expected = "zidryxsckqoxobkvzebzycosxdobzbodonrsqrvofovzbyqbkwwsxqvkxqekqo" self.assertEqual(cipher_text, expected) self.assertEqual(cipher.encrypt("", "a"), "")
def test_encrypt(self): cipher = Caesar() open_text = normalize_text( "Python is a general-purpose, interpreted high-level programming language" ) cipher_text = cipher.encrypt(open_text, "a") self.assertEqual(cipher_text, open_text) cipher_text = cipher.encrypt(open_text, "k") expected = "zidryxsckqoxobkvzebzycosxdobzbodonrsqrvofovzbyqbkwwsxqvkxqekqo" self.assertEqual(cipher_text, expected) self.assertEqual(cipher.encrypt("", "a"), "")
class CaesarBruteForce(object): """Cryptanalysis method for Caesar cipher""" def __init__(self): super(CaesarBruteForce, self).__init__() self.caesar = Caesar() def crack(self, cipher_text, langstats): key_text = ((k,self.caesar.decrypt(cipher_text, k)) for k in string.ascii_lowercase) return langstats.most_meaningful(key_text)
class CaesarBruteForce(object): """Cryptanalysis method for Caesar cipher""" def __init__(self): super(CaesarBruteForce, self).__init__() self.caesar = Caesar() def crack(self, cipher_text, langstats): key_text = ((k, self.caesar.decrypt(cipher_text, k)) for k in string.ascii_lowercase) return langstats.most_meaningful(key_text)
def __init__(self): super(CaesarBruteForce, self).__init__() self.caesar = Caesar()
def __init__(self): super(Vigenere, self).__init__() self.caesar = Caesar()