-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Add autoclave cipher #8029
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
Add autoclave cipher #8029
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please link some documentation at the start of the file and include more doctests within each function
ciphers/autoclave.py
Outdated
@params | ||
plaintext - a normal text to be encrypted (string) | ||
key - a small text or word to start the replacing (sFtring) | ||
|
||
@return | ||
A string with the ciphertext | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@params | |
plaintext - a normal text to be encrypted (string) | |
key - a small text or word to start the replacing (sFtring) | |
@return | |
A string with the ciphertext |
Typically, we want the parameter names to be self-documenting so this isn't really necessary
ciphers/autoclave.py
Outdated
if plaintext == "": | ||
raise ValueError("plaintext is empty") | ||
if key == "": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if plaintext == "": | |
raise ValueError("plaintext is empty") | |
if key == "": | |
if not plaintext: | |
raise ValueError("plaintext is empty") | |
if not key: |
ciphers/autoclave.py
Outdated
if key == "": | ||
raise ValueError("key is empty") | ||
|
||
key = key + plaintext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key = key + plaintext | |
key += plaintext |
ciphers/autoclave.py
Outdated
@@ -0,0 +1,111 @@ | |||
def encrypt(plaintext, key) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def encrypt(plaintext, key) -> str: | |
def encrypt(plaintext, key) -> str: |
These parameters need to be typehinted
ciphers/autoclave.py
Outdated
operation = int(input("Type 1 to encrypt or 2 to decrypt:")) | ||
if operation == 1: | ||
plaintext = str(input("Typeplaintext to be encrypted:\n")) | ||
key = str(input("Type the key:\n")) | ||
print(encrypt(plaintext, key)) | ||
elif operation == 2: | ||
ciphertext = str(input("Type the ciphertext to be decrypted:\n")) | ||
key = str(input("Type the key:\n")) | ||
print(decrypt(ciphertext, key)) | ||
decrypt("jsqqs avvwo", "coffee") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move this into an if __name__ == "__main__":
block
ciphers/autoclave.py
Outdated
@@ -0,0 +1,111 @@ | |||
def encrypt(plaintext, key) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clave is Latin for key so the more popular name for this algorithm is autokey.
def encrypt(plaintext, key) -> str: | |
””” | |
https://en.wikipedia.org/wiki/Autokey_cipher | |
> An autokey cipher (also known as the autoclave cipher) is a cipher that incorporates the message (the plaintext into the key. The key is generated from the message in some automated fashion, sometimes by selecting certain letters from the text or, more commonly, by adding a short primer key to the front of the message. | |
””” | |
def encrypt(plaintext: str, key: str) -> str: |
ciphers/autoclave.py
Outdated
>>> encrypt("hello world", "coffee") | ||
'jsqqs avvwo' | ||
""" | ||
if type(plaintext) != str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: Use isinstance(plaintext, str)
instead of directly comparing types.
for more information, see https://pre-commit.ci
* Add autoclave cipher * Update autoclave with the given suggestions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixing errors * Another fixes * Update and rename autoclave.py to autokey.py * Rename gaussian_naive_bayes.py to gaussian_naive_bayes.py.broken.txt * Rename gradient_boosting_regressor.py to gradient_boosting_regressor.py.broken.txt * Rename random_forest_classifier.py to random_forest_classifier.py.broken.txt * Rename random_forest_regressor.py to random_forest_regressor.py.broken.txt * Rename equal_loudness_filter.py to equal_loudness_filter.py.broken.txt Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
Describe your change:
I'm adding the autoclave or autokey cipher.
Is similar to the vigenerè cipher, but using the own plaintext as the key.
The code implements an encrypt and a decrypt function.
For more info:
https://en.wikipedia.org/wiki/Autokey_cipher
Checklist:
Fixes: #{$ISSUE_NO}
.