From a1c7d57f9d7e6b6bf3e127c050d325adaaf0adc5 Mon Sep 17 00:00:00 2001 From: BMaster123 <88010977+BMaster123@users.noreply.github.com> Date: Mon, 23 Aug 2021 19:15:09 -0500 Subject: [PATCH 1/2] Create baconian_cipher.py --- ciphers/baconian_cipher.py | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 ciphers/baconian_cipher.py diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py new file mode 100644 index 000000000000..1cce97caabbc --- /dev/null +++ b/ciphers/baconian_cipher.py @@ -0,0 +1,68 @@ +"""http://easy-ciphers.com/linkous""" + +bacon_alpha = { + "a": "AAAAA", + "b": "AAAAB", + "c": "AAABA", + "d": "AAABB", + "e": "AABAA", + "f": "AABAB", + "g": "AABBA", + "h": "AABBB", + "i": "ABAAA", + "j": "BBBAA", + "k": "ABAAB", + "l": "ABABA", + "m": "ABABB", + "n": "ABBAA", + "o": "ABBAB", + "p": "ABBBA", + "q": "ABBBB", + "r": "BAAAA", + "s": "BAAAB", + "t": "BAABA", + "u": "BAABB", + "v": "BBBAB", + "w": "BABAA", + "x": "BABAB", + "y": "BABBA", + "z": "BABBB", +} + + +def encrypt(word: str) -> str: + """ + Encrypts the argument + + >>> encrypt("linkous") + 'ABABAABAAAABBAAABAABABBABBAABBBAAAB' + >>> encrypt("rapidum") + 'BAAAAAAAAAABBBAABAAAAAABBBAABBABABB' + """ + word = word.lower() + result = [] + + for char in word: + if char == " ": + result.append(" ") + else: + result.append(bacon_alpha[char]) + + return "".join(result) + + +def decrypt(word: str) -> str: + result = [] + key_list = list(bacon_alpha.keys()) + value_list = list(bacon_alpha.values()) + + word = [word[i : i + 5] for i in range(0, len(word), 5)] + + for i in word: + if i == " ": + result.append(" ") + else: + idx = value_list.index(i) + result.append(key_list[idx]) + + return "".join(result) \ No newline at end of file From da659a5467e1f2416d67e96cddd5841f4c6e9309 Mon Sep 17 00:00:00 2001 From: BMaster123 <88010977+BMaster123@users.noreply.github.com> Date: Mon, 23 Aug 2021 19:18:30 -0500 Subject: [PATCH 2/2] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 1cce97caabbc..1a90f6d22042 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -52,6 +52,12 @@ def encrypt(word: str) -> str: def decrypt(word: str) -> str: + """ + >>> decrypt("ABABAABAAAABBAAABAABABBABBAABBBAAAB") + "linkous" + >>> decrypt("BAAAAAAAAAABBBAABAAAAAABBBAABBABABB") + "rapidum" + """ result = [] key_list = list(bacon_alpha.keys()) value_list = list(bacon_alpha.values())