Skip to content

Added enigma machine emulator #2345

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

Merged
merged 21 commits into from
Aug 26, 2020
Merged

Added enigma machine emulator #2345

merged 21 commits into from
Aug 26, 2020

Conversation

TrapinchO
Copy link
Contributor

@TrapinchO TrapinchO commented Aug 21, 2020

Added Enigma machine file to 'ciphers' section

Describe your change:

Added emulator of the enigma machine from WWII into 'ciphers' folder.

PS: Couldn't open the 'automated testing on Travis CI' in CONTRIBUTING.md. It says

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Added Enigma machine file to 'ciphers' section
@TravisBuddy
Copy link

Hey @TrapinchO,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 3e824c80-e3d4-11ea-ae1e-a7d25f4a9615

@TravisBuddy
Copy link

Hey @TrapinchO,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 99fa2c30-e3d5-11ea-ae1e-a7d25f4a9615

@TravisBuddy
Copy link

Hey @TrapinchO,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: d2718430-e3d7-11ea-ae1e-a7d25f4a9615

@TravisBuddy
Copy link

Travis tests have failed

Hey @TrapinchO,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 4d0d14a0-e3da-11ea-ae1e-a7d25f4a9615

@TrapinchO
Copy link
Contributor Author

I see no log

@TravisBuddy
Copy link

Travis tests have failed

Hey @TrapinchO,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 64aeec30-e3e6-11ea-ae1e-a7d25f4a9615

@TravisBuddy
Copy link

Travis tests have failed

Hey @TrapinchO,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: bf3232b0-e3e7-11ea-ae1e-a7d25f4a9615

@TravisBuddy
Copy link

Travis tests have failed

Hey @TrapinchO,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 3e5bf340-e3e9-11ea-ae1e-a7d25f4a9615

@TravisBuddy
Copy link

Hey @TrapinchO,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: a4a28c30-e3ea-11ea-ae1e-a7d25f4a9615

Comment on lines 94 to 95
raise TypeError('PLugboard setting isn\'t type string ('
+ str(type(pbl)) + ')')
Copy link
Member

@cclauss cclauss Aug 21, 2020

Choose a reason for hiding this comment

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

Suggested change
raise TypeError('PLugboard setting isn\'t type string ('
+ str(type(pbl)) + ')')
raise TypeError(f"Plugboard setting isn't type string ({type(pbl)})")

@TravisBuddy
Copy link

Hey @TrapinchO,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 825b4720-e453-11ea-ae1e-a7d25f4a9615

Added option to separate pair for plugboard by spaces
{'P': 'O', 'O': 'P', 'L': 'A', 'A': 'L', 'N': 'D', 'D': 'N'}

Pairs can be separated by spaces
:param pbl: string containing plugboard setting for the Enigma machine
Copy link
Member

Choose a reason for hiding this comment

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

pblis a cyptic variable name? Why force your reader to guess what it means? Why not use a more self-documenting variable name like pegboard?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thats even more cryptic (at least for me)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is pbstring better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or inputpb

Copy link
Member

Choose a reason for hiding this comment

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

With all these names, the reader will always ask... What does pb stand for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could add it to documentation


Pairs can be separated by spaces
:param pbl: string containing plugboard setting for the Enigma machine
:return: dictionary of
Copy link
Member

Choose a reason for hiding this comment

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

dictionary of ???

Comment on lines 107 to 115
tmppbl = set()
for i in pbl:
if i not in abc:
raise Exception('Not in list of symbols')
elif i in tmppbl:
raise Exception(f'Duplicate symbol ({i})')
else:
tmppbl.add(i)
del tmppbl
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tmppbl = set()
for i in pbl:
if i not in abc:
raise Exception('Not in list of symbols')
elif i in tmppbl:
raise Exception(f'Duplicate symbol ({i})')
else:
tmppbl.add(i)
del tmppbl
if not all(char in abc for char in pbl):
raise ValueError(f'Not characeters are in {abc}')
if len(set(pbl)) != len(pbl):
<your code goes here>

Copy link
Contributor Author

@TrapinchO TrapinchO Aug 22, 2020

Choose a reason for hiding this comment

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

How would you tell the user which symbol is invalid/duplicate?
Improved the invalid symbol exception

Copy link
Member

@cclauss cclauss Aug 26, 2020

Choose a reason for hiding this comment

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

bad_symbols = [key for key, value in collections.Counter(pbl) if key not in abc or value > 1]
if bad_symbols:
    raise ValueError(<your code here>)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think my version is easier to understand

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

Thanks!!

@cclauss cclauss merged commit 30126c2 into TheAlgorithms:master Aug 26, 2020
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Added Enigma machine file

Added Enigma machine file to 'ciphers' section

* Added doctest to validator

* Fixed typo

* Shortened some lines

* Shortened some lines

* Update enigma_machine.py

* Shortened some lines

* Update enigma_machine.py

* Update enigma_machine.py

* Update enigma_machine2.py

* Update enigma_machine2.py

* added f-strings

* Update enigma_machine2.py

* Update enigma_machine2.py

* Updated some numbers

* Plugboard improvement

Added option to separate pair for plugboard by spaces

* renamed variable

* renamed some variables

* improved plugboard exception

* Update enigma_machine2.py

* Update enigma_machine2.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants