Exemplo n.º 1
0
 def test_autokey_interrupter(self):
     key = np.array([20, 10, 17, 18, 4])  # Liber
     interrupter = 0
     ct = enc.autokey_encryption(tt.get_koan2_plaintext(), interrupter, key)
     interrupter_array = np.asarray(tt.get_koan2_plaintext() == interrupter,
                                    dtype=bool)
     mt = hpf.decryption_autokey(key, ct, interrupter_array)
     mt = mt.squeeze()
     np.testing.assert_array_equal(tt.get_koan2_plaintext(), mt)
Exemplo n.º 2
0
 def test_vigenere_decryption_koan2(self):
     interrupter = 0
     plaintext = tt.get_koan2_plaintext()
     ct = tt.get_koan2_text()
     hpf.main(algorithm=0,
              shift_id=0,
              reversed_text=False,
              reverse_gematria=False,
              interrupter=interrupter,
              ciphertext=ct)
     df = pd.read_csv('keys.txt', sep=',')
     self.assertEqual(
         hpf.translate_to_english(tt.get_koan2_plaintext(),
                                  reverse_gematria=False),
         df.loc[0, 'Message text'])
Exemplo n.º 3
0
 def test_vigenere_encryption(self):
     interrupter = 0
     plaintext = tt.get_koan2_plaintext()
     ct = plaintext.copy()
     key = np.array([0, 10, 4, 0, 1, 19, 0, 18, 4, 18, 9, 0, 18])  # FIRFUMFERENFE
     ct = enc.vigenere_encryption(ct, interrupter, key)
     np.testing.assert_array_equal(tt.get_koan2_text(), ct)
Exemplo n.º 4
0
    def test_autokey_full(self):
        key = np.array([20, 10, 17, 18, 4])  # Liber
        interrupter = 0
        ct = enc.autokey_encryption(tt.get_koan2_plaintext(), interrupter, key)

        hpf.main(algorithm=1,
                 shift_id=0,
                 reversed_text=False,
                 reverse_gematria=False,
                 interrupter=0,
                 ciphertext=ct)
        df = pd.read_csv('keys.txt', sep=',')
        self.assertEqual(
            hpf.translate_to_english(tt.get_koan2_plaintext(),
                                     reverse_gematria=False),
            df.loc[0, 'Message text'])
Exemplo n.º 5
0
 def test_autokey_encryption_beginning(self):
     interrupter = 0
     plaintext = tt.get_koan2_plaintext()
     ct = plaintext.copy()
     key = np.array([0, 10, 4, 0, 1, 19, 0, 18, 4, 18, 9, 0, 18])  # FIRFUMFERENFE
     ct_autokey = enc.autokey_encryption(ct, interrupter, key)
     ct_vigenere = enc.vigenere_encryption(ct, interrupter, key)
     np.testing.assert_array_equal(ct_autokey[0:len(key)], ct_vigenere[0:len(key)])
Exemplo n.º 6
0
 def test_pure_vigenere_decryption(self):
     interrupter = 0
     key = np.array([[0, 10, 4, 0, 1, 19, 0, 18, 4, 18, 9, 0, 18]])
     plaintext = tt.get_koan2_plaintext()
     ct = tt.get_koan2_text()
     interrupter_array = (plaintext == interrupter).astype(int)
     mt = hpf.decryption_vigenere(key, ct, interrupter_array)
     np.testing.assert_array_equal(plaintext, np.squeeze(mt))
Exemplo n.º 7
0
 def test_full_encrypt_text(self):
     interrupter = 0
     plaintext = tt.get_koan2_plaintext()
     key = np.array([0, 10, 4, 0, 1, 19, 0, 18, 4, 18, 9, 0, 18])  # FIRFUMFERENFE
     algorithm = 'Vigenere'
     reverse_text = False
     reverse_gematria = False
     shift_id = 0
     interrupter_array = np.asarray(plaintext == interrupter, dtype=int)
     ct = enc.encrypt_text(plaintext, algorithm, shift_id, reverse_text, reverse_gematria, interrupter, key, interrupter_array)
     np.testing.assert_array_equal(tt.get_koan2_text(), ct)
Exemplo n.º 8
0
 def test_autokey_shift0(self):
     interrupter = 0
     ct_numbers = tt.get_koan2_plaintext()
     interrupter_array = np.asarray(ct_numbers == interrupter)
     ciphertext = enc.encrypt_text(plaintext=ct_numbers,
                                   algorithm='Autokey',
                                   shift_id=0,
                                   reverse_text=False,
                                   reverse_gematria=False,
                                   interrupter=interrupter,
                                   key=np.array(
                                       [0, 10, 15, 8, 18, 4, 19, 24, 9]),
                                   interrupter_array=interrupter_array)
     hpf.main(algorithm=1,
              shift_id=0,
              reversed_text=False,
              reverse_gematria=False,
              interrupter=interrupter,
              ciphertext=ciphertext)
     df = pd.read_csv('keys.txt', sep=',')
     self.assertEqual(
         hpf.translate_to_english(tt.get_koan2_plaintext(),
                                  reverse_gematria=False),
         df.loc[0, 'Message text'])