コード例 #1
0
 def test_key_is_valid(self):
     valid_keys = [-100, 100, 0]
     invalid_keys = [{'a': 'b', 'b': 'c'}, 'aeiou', []]
     cipher = substitution.CaesarCipher()
     for key in valid_keys:
         assert cipher.key_is_valid(key)
     for key in invalid_keys:
         assert not cipher.key_is_valid(key)
コード例 #2
0
 def test_no_shift(self):
     cipher = substitution.CaesarCipher()
     plaintext = FOX_TEXT
     ciphertext = cipher.encrypt(plaintext, 0)
     assert plaintext == ciphertext
コード例 #3
0
 def test_random_key(self):
     cipher = substitution.CaesarCipher()
     for i in range(100):
         key = substitution.get_random_caesar_key()
         assert cipher.key_is_valid(key)
コード例 #4
0
 def test_decrypt_neg_25(self):
     cipher = substitution.CaesarCipher()
     ciphertext = SHIFT_1
     plaintext = cipher.decrypt(ciphertext, -25)
     assert plaintext == FOX_TEXT
コード例 #5
0
 def test_shift_raises_exception_with_invalid_key(self):
     cipher = substitution.CaesarCipher()
     with pytest.raises(exceptions.InvalidKeyException):
         cipher.encrypt('abc', {'a': 'b', 'b': 'c'})
コード例 #6
0
 def test_shift_back_27(self):
     cipher = substitution.CaesarCipher()
     plaintext = FOX_TEXT
     ciphertext = cipher.encrypt(plaintext, -27)
     assert ciphertext == SHIFT_25
コード例 #7
0
 def test_shift_26(self):
     cipher = substitution.CaesarCipher()
     plaintext = FOX_TEXT
     ciphertext = cipher.encrypt(plaintext, 26)
     assert ciphertext == plaintext