def test_znajdz_klucz(self): tekst_do_zaszyfrowania = """ The idea behind the Vigenère cipher, like all polyalphabetic ciphers, is to disguise plaintext letter frequencies, which interferes with a straightforward application of frequency analysis. For instance, if P is the most frequent letter in a ciphertext whose plaintext is in English, one might suspect that P corresponds to E, because E is the most frequently used letter in English. However, using the Vigenère cipher, E can be enciphered as different ciphertext letters at different points in the message, thus defeating simple frequency analysis. The primary weakness of the Vigenère cipher is the repeating nature of its key. If a cryptanalyst correctly guesses the key's length, then the cipher text can be treated as interwoven Caesar ciphers, which individually are easily broken. The Kasiski and Friedman tests can help determine the key length. """ zaszyfrowany_tekst = vigner.zaszyfruj_tekst(vigner.przygotuj_tekst(tekst_do_zaszyfrowania), "secret") dlugosc_klucza = 6 self.assertEqual(vigner.znajdz_klucz(zaszyfrowany_tekst, dlugosc_klucza), "secret")
def test_przygotuj_tekst(self): self.assertEqual('testowyprzypadek', vigner.przygotuj_tekst('&Te3[]stowy P93820rz9098yp....ad____e+_+_//k')) self.assertEqual('zolw', vigner.przygotuj_tekst('żzóołlw')) self.assertEqual('test', vigner.przygotuj_tekst('(TEST)'))
def test_odczytaj_klucz_z_pliku(self): klucz = vigner.odczytaj_plik('key.txt') self.assertEqual(vigner.przygotuj_tekst(klucz), 'secret')