From 4d352481726425ad09bea86315101deedb38c6ad Mon Sep 17 00:00:00 2001 From: gabriellypinto Date: Sat, 7 Oct 2023 11:22:14 -0300 Subject: [PATCH] add tests for enigma_machine --- hashes/enigma_machine.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/hashes/enigma_machine.py b/hashes/enigma_machine.py index d95437d12..7c68ecf24 100644 --- a/hashes/enigma_machine.py +++ b/hashes/enigma_machine.py @@ -1,3 +1,11 @@ +""" + +Note: + This algorithm has memory persistance. + So multiple runs on the same runtime will carry junk and scramble the result! +""" + + alphabets = [chr(i) for i in range(32, 126)] gear_one = list(range(len(alphabets))) gear_two = list(range(len(alphabets))) @@ -40,7 +48,22 @@ def engine(input_character): rotator() -if __name__ == "__main__": +def encode_or_decode(message, token): + """ + + >>> encode_or_decode("hello", 3) + (['/', '0', "'", '%', ' '], 3) + + """ + + for _ in range(token): + rotator() + for j in message: + engine(j) + return code, token + + +def menu(): decode = list(input("Type your message:\n")) while True: try: @@ -57,3 +80,10 @@ if __name__ == "__main__": f"\nYour Token is {token} please write it down.\nIf you want to decode " "this message again you should input same digits as token!" ) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() +