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

Add autoclave cipher #8029

Merged
merged 11 commits into from
Dec 18, 2022
Prev Previous commit
Next Next commit
Update and rename autoclave.py to autokey.py
  • Loading branch information
cclauss committed Dec 18, 2022
commit b72a63664dc9353476d7fb7298ce534294fc55fc
21 changes: 12 additions & 9 deletions ciphers/autoclave.py → ciphers/autokey.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
https://en.wikipedia.org/wiki/Autokey_cipher
> An autokey cipher (also known as the autoclave cipher) is a cipher that
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,
Expand All @@ -10,8 +10,8 @@

def encrypt(plaintext: str, key: str) -> str:
"""
Function that encrypt a given plaintext (string)
and key (string), returning the encrypted ciphertext
Encrypt a given plaintext (string) and key (string), returning the
encrypted ciphertext.
>>> encrypt("hello world", "coffee")
'jsqqs avvwo'
>>> encrypt("coffee is good as python", "TheAlgorithms")
Expand Down Expand Up @@ -66,8 +66,8 @@ def encrypt(plaintext: str, key: str) -> str:

def decrypt(ciphertext: str, key: str) -> str:
"""
Function that decrypt a given ciphertext (string)
and key (string), returning the decrypted ciphertext
Decrypt a given ciphertext (string) and key (string), returning the decrypted
ciphertext.
>>> decrypt("jsqqs avvwo", "coffee")
'hello world'
>>> decrypt("vvjfpk wj ohvp su ddylsv", "TheAlgorithms")
Expand Down Expand Up @@ -116,13 +116,16 @@ def decrypt(ciphertext: str, key: str) -> str:


if __name__ == "__main__":
import doctest

doctest.testmod()
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"))
plaintext = input("Typeplaintext to be encrypted:\n")
key = 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"))
ciphertext = input("Type the ciphertext to be decrypted:\n")
key = input("Type the key:\n")
print(decrypt(ciphertext, key))
decrypt("jsqqs avvwo", "coffee")