Skip to content

add tests for enigma_machine #10017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion hashes/enigma_machine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""

Note:
This algorithm has memory persistence.
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)))
Expand Down Expand Up @@ -40,7 +48,22 @@ def engine(input_character):
rotator()


if __name__ == "__main__":
def encode_or_decode(message, token):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just the body of the driver code? Why is it not used in the driver code?

Also, please add type hints

"""

>>> encode_or_decode("hello", 3)
(['/', '0', "'", '%', ' '], 3)

"""

for _ in range(token):
rotator()
for j in message:
engine(j)
return code, token


def menu():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code chunk is all driver code, so it's fine to keep it in the __main__ block.

decode = list(input("Type your message:\n"))
while True:
try:
Expand All @@ -57,3 +80,9 @@ def engine(input_character):
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()