/
test_cipher.py
27 lines (20 loc) · 910 Bytes
/
test_cipher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from capstone.text.cipher import VigenereCipher, VernamCipher, CaesarCipher
class TestCipher:
def test_vigenere_cipher(self):
cipher = VigenereCipher("LEMON")
plaintext = "ATTACKATDAWN"
ciphertext = cipher.encrypt(plaintext)
assert ciphertext == "LXFOPVEFRNHR"
assert cipher.decrypt(ciphertext) == plaintext
def test_vernam_cipher(self):
cipher = VernamCipher("AXHJB")
plaintext = "HELLO"
ciphertext = cipher.encrypt(plaintext)
assert ciphertext == "QMIBE"
assert cipher.decrypt(ciphertext) == plaintext
def test_caesar_cipher(self):
cipher = CaesarCipher(-3)
plaintext = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
ciphertext = cipher.encrypt(plaintext)
assert ciphertext == "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD"
assert cipher.decrypt(ciphertext) == plaintext