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)
def test_no_shift(self): cipher = substitution.CaesarCipher() plaintext = FOX_TEXT ciphertext = cipher.encrypt(plaintext, 0) assert plaintext == ciphertext
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)
def test_decrypt_neg_25(self): cipher = substitution.CaesarCipher() ciphertext = SHIFT_1 plaintext = cipher.decrypt(ciphertext, -25) assert plaintext == FOX_TEXT
def test_shift_raises_exception_with_invalid_key(self): cipher = substitution.CaesarCipher() with pytest.raises(exceptions.InvalidKeyException): cipher.encrypt('abc', {'a': 'b', 'b': 'c'})
def test_shift_back_27(self): cipher = substitution.CaesarCipher() plaintext = FOX_TEXT ciphertext = cipher.encrypt(plaintext, -27) assert ciphertext == SHIFT_25
def test_shift_26(self): cipher = substitution.CaesarCipher() plaintext = FOX_TEXT ciphertext = cipher.encrypt(plaintext, 26) assert ciphertext == plaintext