-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
40 lines (28 loc) · 1.2 KB
/
main.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
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Example usage demonstration script.
Simple showcase of the three cipher classes implemented in this project
"""
from src.message_cipher.affine_cipher import AffineCipher
from src.message_cipher.caesar_cipher import CaesarCipher
from src.message_cipher.cipher import Cipher
from src.message_cipher.rsa_system import RSA
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def test_cipher(cipher: Cipher, message: str) -> None:
"""Runs the given cipher with some example input.
:param cipher: Any of ``CaesarCipher``, ``AffineCipher``, or ``RSA``.
"""
ciphertext = cipher.encrypt(message)
plaintext = cipher.decrypt(ciphertext)
print('"' + message + '"' + " ->", cipher, "->", ciphertext)
print('"' + str(ciphertext) + '"' + " ->", cipher, "->", plaintext)
print()
def main() -> None:
"""Demonstrate the capabilities of MessageCipher package."""
message = input("Enter a message to encrypt: ")
test_cipher(AffineCipher(5, 13), message)
test_cipher(AffineCipher(7, 19), message)
test_cipher(CaesarCipher(11), message)
test_cipher(CaesarCipher(23), message)
test_cipher(RSA(5, 7), message)
test_cipher(RSA(13, 23), message)
if __name__ == "__main__":
main()