Skip to content
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

Added enigma machine emulator #2345

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 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}.
TrapinchO added 2 commits Aug 21, 2020
Added Enigma machine file to 'ciphers' section
@TravisBuddy
Copy link

TravisBuddy commented Aug 21, 2020

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

TravisBuddy commented Aug 21, 2020

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

TravisBuddy commented Aug 21, 2020

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

TravisBuddy commented Aug 21, 2020

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

TrapinchO commented Aug 21, 2020

I see no log

@TravisBuddy
Copy link

TravisBuddy commented Aug 21, 2020

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

TravisBuddy commented Aug 21, 2020

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

TravisBuddy commented Aug 21, 2020

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

TravisBuddy commented Aug 21, 2020

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
ciphers/enigma_machine2.py Outdated Show resolved Hide resolved
ciphers/enigma_machine2.py Outdated Show resolved Hide resolved
ciphers/enigma_machine2.py Outdated Show resolved Hide resolved
raise TypeError('PLugboard setting isn\'t type string ('
+ str(type(pbl)) + ')')
Comment on lines 94 to 95

This comment has been minimized.

@cclauss

cclauss Aug 21, 2020

Member
Suggested change
raise TypeError('PLugboard setting isn\'t type string ('
+ str(type(pbl)) + ')')
raise TypeError(f"Plugboard setting isn't type string ({type(pbl)})")
ciphers/enigma_machine2.py Outdated Show resolved Hide resolved
@TravisBuddy
Copy link

TravisBuddy commented Aug 22, 2020

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
TrapinchO added 2 commits Aug 22, 2020
ciphers/enigma_machine2.py Outdated Show resolved Hide resolved
ciphers/enigma_machine2.py Outdated Show resolved Hide resolved
ciphers/enigma_machine2.py Outdated Show resolved Hide resolved
TrapinchO added 2 commits Aug 22, 2020
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

This comment has been minimized.

@cclauss

cclauss Aug 22, 2020

Member

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?

This comment has been minimized.

@TrapinchO

TrapinchO Aug 22, 2020

Author Contributor

thats even more cryptic (at least for me)

This comment has been minimized.

@TrapinchO

TrapinchO Aug 22, 2020

Author Contributor

is pbstring better?

This comment has been minimized.

@TrapinchO

TrapinchO Aug 22, 2020

Author Contributor

or inputpb

This comment has been minimized.

@cclauss

cclauss Aug 22, 2020

Member

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

This comment has been minimized.

@TrapinchO

TrapinchO Aug 22, 2020

Author Contributor

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

This comment has been minimized.

@cclauss

cclauss Aug 22, 2020

Member

dictionary of ???

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
Comment on lines 107 to 115

This comment has been minimized.

@cclauss

cclauss Aug 22, 2020

Member
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>

This comment has been minimized.

@TrapinchO

TrapinchO Aug 22, 2020

Author Contributor

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

This comment has been minimized.

@cclauss

cclauss Aug 26, 2020

Member
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>)

This comment has been minimized.

@TrapinchO

TrapinchO Aug 26, 2020

Author Contributor

I think my version is easier to understand

Copy link
Member

cclauss left a comment

Thanks!!

@cclauss cclauss merged commit 30126c2 into TheAlgorithms:master Aug 26, 2020
2 checks passed
2 checks passed
codespell
Details
Travis CI - Pull Request Build Passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.