From d087155c60c38671b453df6075d895f4d37ecd22 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 01:39:01 +0530 Subject: [PATCH 01/34] Create baconian_cipher.py --- ciphers/baconian_cipher.py | 93 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 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..c85bbcb5d52a --- /dev/null +++ b/ciphers/baconian_cipher.py @@ -0,0 +1,93 @@ +""" +Program to encode and decode Baconian or Bacon's Cipher +Wikipedia reference : https://en.wikipedia.org/wiki/Bacon%27s_cipher +""" + +encode_dict = { + "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", + " ": " " +} + + +decode_dict = {} + + +for alphabet in encode_dict: + decode_dict[encode_dict[alphabet]] = alphabet + + +def encode(word: str) -> str: + """ + Encodes to Baconian cipher + >>> encode("hello") + 'AABBBAABAAABABAABABAABBAB' + >>> encode("hello world") + 'AABBBAABAAABABAABABAABBAB BABAAABBABBAAAAABABAAAABB' + >>> encode("hello world!") + Traceback (most recent call last): + ... + Exception: encode() accepts only alphabets + """ + encoded = '' + for letter in word.lower(): + if letter.isalpha() or letter == " ": + encoded += encode_dict[letter] + else: + raise Exception("encode() accepts only alphabets") + return encoded + +def decode(coded: str) -> str: + """ + Decodes from Baconian cipher + + >>> decode("AABBBAABAAABABAABABAABBAB BABAAABBABBAAAAABABAAAABB") + 'hello world' + >>> decode("AABBBAABAAABABAABABAABBAB") + 'hello' + >>> encode("AABBBAABAAABABAABABAABBAB BABAAABBABBAAAAABABAAAABB!") + Traceback (most recent call last): + ... + Exception: encode() accepts only alphabets + """ + words = coded.split() + if (set(coded) - {'A', 'B', ' '} != set() and set(coded) - {'A', 'B'} != set()) + raise Exception("decode accepts only 'A', 'B' and ' '") + words = coded.split() + decoded = '' + for word in words: + while len(word) != 0: + decoded += decode_dict[word[:5]] + word = word[5:] + decoded += ' ' + decoded = decoded.strip(' ') + return decoded + +if "__name__" == "__main__": + from doctest import testmod + + testmod() From 203f127da67461e090cec115e5cc827ca9145198 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 01:43:01 +0530 Subject: [PATCH 02/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index c85bbcb5d52a..9cf1913e6ef3 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -54,12 +54,12 @@ def encode(word: str) -> str: Exception: encode() accepts only alphabets """ encoded = '' - for letter in word.lower(): - if letter.isalpha() or letter == " ": - encoded += encode_dict[letter] - else: - raise Exception("encode() accepts only alphabets") - return encoded + for letter in word.lower(): + if letter.isalpha() or letter == " ": + encoded += encode_dict[letter] + else: + raise Exception("encode() accepts only alphabets") + return encoded def decode(coded: str) -> str: """ @@ -74,18 +74,17 @@ def decode(coded: str) -> str: ... Exception: encode() accepts only alphabets """ + if set(coded) - {'A', 'B', ' '} != set() and set(coded) - {'A', 'B'} != set(): + raise Exception("decode accepts only 'A', 'B' and ' '") words = coded.split() - if (set(coded) - {'A', 'B', ' '} != set() and set(coded) - {'A', 'B'} != set()) - raise Exception("decode accepts only 'A', 'B' and ' '") - words = coded.split() - decoded = '' - for word in words: - while len(word) != 0: - decoded += decode_dict[word[:5]] - word = word[5:] - decoded += ' ' + decoded = '' + for word in words: + while len(word) != 0: + decoded += decode_dict[word[:5]] + word = word[5:] + decoded += ' ' decoded = decoded.strip(' ') - return decoded + return decoded if "__name__" == "__main__": from doctest import testmod From 7b19ebf9ba1613ffa21bb218a4185ef1b6342290 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 01:47:11 +0530 Subject: [PATCH 03/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 9cf1913e6ef3..63714aefb12a 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -35,8 +35,6 @@ decode_dict = {} - - for alphabet in encode_dict: decode_dict[encode_dict[alphabet]] = alphabet From ca64585160ec066ab949b7a0462ec313a87fa8e0 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 01:49:36 +0530 Subject: [PATCH 04/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 63714aefb12a..92fc568b61fb 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -53,9 +53,9 @@ def encode(word: str) -> str: """ encoded = '' for letter in word.lower(): - if letter.isalpha() or letter == " ": + if letter.isalpha() or letter == " ": encoded += encode_dict[letter] - else: + else: raise Exception("encode() accepts only alphabets") return encoded From 8045dd713ea191436e30a59d77a30a9cff31ac98 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 01:54:24 +0530 Subject: [PATCH 05/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 92fc568b61fb..1ec9634a644c 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -53,7 +53,7 @@ def encode(word: str) -> str: """ encoded = '' for letter in word.lower(): - if letter.isalpha() or letter == " ": + if letter.isalpha() or letter == " ": encoded += encode_dict[letter] else: raise Exception("encode() accepts only alphabets") From a5797d4d521fee91d4978cc903d96321ac47031f Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 01:56:53 +0530 Subject: [PATCH 06/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 1ec9634a644c..3701a715d9e2 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -53,10 +53,10 @@ def encode(word: str) -> str: """ encoded = '' for letter in word.lower(): - if letter.isalpha() or letter == " ": - encoded += encode_dict[letter] - else: - raise Exception("encode() accepts only alphabets") + if letter.isalpha() or letter == " ": + encoded += encode_dict[letter] + else: + raise Exception("encode() accepts only alphabets") return encoded def decode(coded: str) -> str: From 0996953560d97aa6e17c3ab435ed43796f82d57c Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 01:58:04 +0530 Subject: [PATCH 07/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 3701a715d9e2..8f0eece36a1b 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -54,7 +54,7 @@ def encode(word: str) -> str: encoded = '' for letter in word.lower(): if letter.isalpha() or letter == " ": - encoded += encode_dict[letter] + encoded += encode_dict[letter] else: raise Exception("encode() accepts only alphabets") return encoded From 1a2c7a70add4b5713e8f4109f05b780d174b46f3 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:03:38 +0530 Subject: [PATCH 08/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 8f0eece36a1b..92fc568b61fb 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -53,10 +53,10 @@ def encode(word: str) -> str: """ encoded = '' for letter in word.lower(): - if letter.isalpha() or letter == " ": - encoded += encode_dict[letter] - else: - raise Exception("encode() accepts only alphabets") + if letter.isalpha() or letter == " ": + encoded += encode_dict[letter] + else: + raise Exception("encode() accepts only alphabets") return encoded def decode(coded: str) -> str: From e39e02ba1ce6b9a9e95d60d43d1832c6e968acb7 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:05:06 +0530 Subject: [PATCH 09/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 92fc568b61fb..8060bb878078 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -54,9 +54,9 @@ def encode(word: str) -> str: encoded = '' for letter in word.lower(): if letter.isalpha() or letter == " ": - encoded += encode_dict[letter] + encoded += encode_dict[letter] else: - raise Exception("encode() accepts only alphabets") + raise Exception("encode() accepts only alphabets") return encoded def decode(coded: str) -> str: From 3c40713e6cf8fd4159d528489b4a957979c9dae1 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:09:07 +0530 Subject: [PATCH 10/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 8060bb878078..bed75c665eb0 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -53,10 +53,10 @@ def encode(word: str) -> str: """ encoded = '' for letter in word.lower(): - if letter.isalpha() or letter == " ": - encoded += encode_dict[letter] - else: - raise Exception("encode() accepts only alphabets") + if letter.isalpha() or letter == " ": + encoded += encode_dict[letter] + else: + raise Exception("encode() accepts only alphabets") return encoded def decode(coded: str) -> str: From 09dfe50d2127be0cd15c12f51ea5f43134f8740b Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:10:49 +0530 Subject: [PATCH 11/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index bed75c665eb0..10812124a923 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -53,9 +53,9 @@ def encode(word: str) -> str: """ encoded = '' for letter in word.lower(): - if letter.isalpha() or letter == " ": + if letter.isalpha() or letter == " ": encoded += encode_dict[letter] - else: + else: raise Exception("encode() accepts only alphabets") return encoded @@ -80,7 +80,7 @@ def decode(coded: str) -> str: while len(word) != 0: decoded += decode_dict[word[:5]] word = word[5:] - decoded += ' ' + decoded += ' ' decoded = decoded.strip(' ') return decoded From e2a8883eca393a7a80464c3270ee77bb4e2203ff Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:12:02 +0530 Subject: [PATCH 12/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 10812124a923..5e2df53c4e3c 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -52,8 +52,8 @@ def encode(word: str) -> str: Exception: encode() accepts only alphabets """ encoded = '' - for letter in word.lower(): - if letter.isalpha() or letter == " ": + for letter in word.lower() : + if letter.isalpha() or letter == " " : encoded += encode_dict[letter] else: raise Exception("encode() accepts only alphabets") From 6ddfc1e295cf07e433daecb2bfa432bafe96acee Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:21:44 +0530 Subject: [PATCH 13/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 5e2df53c4e3c..f87c35c0b271 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -42,6 +42,7 @@ def encode(word: str) -> str: """ Encodes to Baconian cipher + >>> encode("hello") 'AABBBAABAAABABAABABAABBAB' >>> encode("hello world") From 65eda7de654ce59e7041ddaa00230e2d46fe88dd Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:33:17 +0530 Subject: [PATCH 14/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index f87c35c0b271..2d70d58556a4 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -33,12 +33,10 @@ " ": " " } - decode_dict = {} for alphabet in encode_dict: decode_dict[encode_dict[alphabet]] = alphabet - def encode(word: str) -> str: """ Encodes to Baconian cipher @@ -52,14 +50,14 @@ def encode(word: str) -> str: ... Exception: encode() accepts only alphabets """ - encoded = '' - for letter in word.lower() : - if letter.isalpha() or letter == " " : - encoded += encode_dict[letter] + encoded = "" + for letter in word.lower(): + if letter.isalpha() or letter == " ": + encoded += encode_dict[letter] else: - raise Exception("encode() accepts only alphabets") + raise Exception("encode() accepts only alphabets") return encoded - + def decode(coded: str) -> str: """ Decodes from Baconian cipher @@ -76,16 +74,16 @@ def decode(coded: str) -> str: if set(coded) - {'A', 'B', ' '} != set() and set(coded) - {'A', 'B'} != set(): raise Exception("decode accepts only 'A', 'B' and ' '") words = coded.split() - decoded = '' + decoded = "" for word in words: while len(word) != 0: - decoded += decode_dict[word[:5]] + decoded += decode_dict[word[:5]] word = word[5:] - decoded += ' ' - decoded = decoded.strip(' ') + decoded += " " + decoded = decoded.strip(" ") return decoded if "__name__" == "__main__": from doctest import testmod - + testmod() From 0c3d668f5eaf4099f04bafc499b18c7364bf9adb Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:34:52 +0530 Subject: [PATCH 15/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 2d70d58556a4..b8b474ee15ba 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -77,9 +77,9 @@ def decode(coded: str) -> str: decoded = "" for word in words: while len(word) != 0: - decoded += decode_dict[word[:5]] + decoded += decode_dict[word[:5]] word = word[5:] - decoded += " " + decoded += " " decoded = decoded.strip(" ") return decoded From 3676c27b10f849087d657077dd7db0897c72a933 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:39:04 +0530 Subject: [PATCH 16/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index b8b474ee15ba..3a577b31c18b 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -76,10 +76,9 @@ def decode(coded: str) -> str: words = coded.split() decoded = "" for word in words: - while len(word) != 0: - decoded += decode_dict[word[:5]] - word = word[5:] - decoded += " " + while len(word) > 0: + decoded += decode_dict[word[:5]] + decoded += " " decoded = decoded.strip(" ") return decoded From 621f5e5c5a5fc27ad23428af6f2dee9a6a9362a7 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:44:56 +0530 Subject: [PATCH 17/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 3a577b31c18b..69dfb54cfa4f 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -30,17 +30,18 @@ "x": "BABAB", "y": "BABBA", "z": "BABBB", - " ": " " + " ": " ", } decode_dict = {} for alphabet in encode_dict: decode_dict[encode_dict[alphabet]] = alphabet + def encode(word: str) -> str: """ Encodes to Baconian cipher - + >>> encode("hello") 'AABBBAABAAABABAABABAABBAB' >>> encode("hello world") @@ -53,15 +54,16 @@ def encode(word: str) -> str: encoded = "" for letter in word.lower(): if letter.isalpha() or letter == " ": - encoded += encode_dict[letter] + encoded += encode_dict[letter] else: - raise Exception("encode() accepts only alphabets") + raise Exception("encode() accepts only alphabets") return encoded - + + def decode(coded: str) -> str: """ Decodes from Baconian cipher - + >>> decode("AABBBAABAAABABAABABAABBAB BABAAABBABBAAAAABABAAAABB") 'hello world' >>> decode("AABBBAABAAABABAABABAABBAB") @@ -71,7 +73,7 @@ def decode(coded: str) -> str: ... Exception: encode() accepts only alphabets """ - if set(coded) - {'A', 'B', ' '} != set() and set(coded) - {'A', 'B'} != set(): + if set(coded) - {"A", "B", " "} != set() and set(coded) - {"A", "B"} != set(): raise Exception("decode accepts only 'A', 'B' and ' '") words = coded.split() decoded = "" @@ -82,7 +84,8 @@ def decode(coded: str) -> str: decoded = decoded.strip(" ") return decoded + if "__name__" == "__main__": from doctest import testmod - + testmod() From 71514ce518d40dcfe5a18570fb6233fb5eaa6767 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:49:26 +0530 Subject: [PATCH 18/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 69dfb54cfa4f..20db52ac311b 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -78,7 +78,7 @@ def decode(coded: str) -> str: words = coded.split() decoded = "" for word in words: - while len(word) > 0: + while len(word) == 5: decoded += decode_dict[word[:5]] decoded += " " decoded = decoded.strip(" ") From e89bd55dd6bf7a09e85eb36707da96419919fbf3 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:50:16 +0530 Subject: [PATCH 19/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 20db52ac311b..86fc3a21c810 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -78,7 +78,7 @@ def decode(coded: str) -> str: words = coded.split() decoded = "" for word in words: - while len(word) == 5: + while len(word) != 5: decoded += decode_dict[word[:5]] decoded += " " decoded = decoded.strip(" ") From fda5dc8262ec57bbffd4223ed2232cd41f0099eb Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 02:56:00 +0530 Subject: [PATCH 20/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 86fc3a21c810..1e5f93ddea2b 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -78,7 +78,7 @@ def decode(coded: str) -> str: words = coded.split() decoded = "" for word in words: - while len(word) != 5: + while len(word) != 0: decoded += decode_dict[word[:5]] decoded += " " decoded = decoded.strip(" ") From 9d142379c61a02db3bef629423261b6c5e2b2f4e Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 03:11:39 +0530 Subject: [PATCH 21/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 1e5f93ddea2b..54c3a2a43a27 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -80,6 +80,7 @@ def decode(coded: str) -> str: for word in words: while len(word) != 0: decoded += decode_dict[word[:5]] + word = word[5:] decoded += " " decoded = decoded.strip(" ") return decoded From 18db6a539f01166979b0b9d5d59be527453dcf9a Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 04:33:26 +0530 Subject: [PATCH 22/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 54c3a2a43a27..744cb29e58b6 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -59,7 +59,6 @@ def encode(word: str) -> str: raise Exception("encode() accepts only alphabets") return encoded - def decode(coded: str) -> str: """ Decodes from Baconian cipher From 73c1553e00036d3bbd09eae732c9442498e81e5f Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 04:34:48 +0530 Subject: [PATCH 23/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 744cb29e58b6..54c3a2a43a27 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -59,6 +59,7 @@ def encode(word: str) -> str: raise Exception("encode() accepts only alphabets") return encoded + def decode(coded: str) -> str: """ Decodes from Baconian cipher From a51d545139b91c7f363689576179d5be54880b6f Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 04:43:15 +0530 Subject: [PATCH 24/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 54c3a2a43a27..ceb30d5a643c 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -30,8 +30,7 @@ "x": "BABAB", "y": "BABBA", "z": "BABBB", - " ": " ", -} + " ": " ",} decode_dict = {} for alphabet in encode_dict: From 61989072f3e0b89308bc379ef375dea5af205f15 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Tue, 12 Oct 2021 04:46:57 +0530 Subject: [PATCH 25/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index ceb30d5a643c..54c3a2a43a27 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -30,7 +30,8 @@ "x": "BABAB", "y": "BABBA", "z": "BABBB", - " ": " ",} + " ": " ", +} decode_dict = {} for alphabet in encode_dict: From 04be254bda1659c46c854bc34e994f1a2cefaa9a Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Thu, 14 Oct 2021 18:23:07 +0530 Subject: [PATCH 26/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 54c3a2a43a27..ec213e8a6002 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -33,9 +33,7 @@ " ": " ", } -decode_dict = {} -for alphabet in encode_dict: - decode_dict[encode_dict[alphabet]] = alphabet +decode_dict = {value : key for key, value in encode_dict.items()} def encode(word: str) -> str: @@ -49,14 +47,14 @@ def encode(word: str) -> str: >>> encode("hello world!") Traceback (most recent call last): ... - Exception: encode() accepts only alphabets + Exception: encode() accepts only letters of the alphabet and spaces """ encoded = "" for letter in word.lower(): if letter.isalpha() or letter == " ": encoded += encode_dict[letter] else: - raise Exception("encode() accepts only alphabets") + raise Exception("encode() accepts only letters of the alphabet and spaces") return encoded @@ -75,15 +73,13 @@ def decode(coded: str) -> str: """ if set(coded) - {"A", "B", " "} != set() and set(coded) - {"A", "B"} != set(): raise Exception("decode accepts only 'A', 'B' and ' '") - words = coded.split() - decoded = "" - for word in words: + decoded = "" + for word in coded.split(): while len(word) != 0: decoded += decode_dict[word[:5]] word = word[5:] decoded += " " - decoded = decoded.strip(" ") - return decoded + return decoded.strip() if "__name__" == "__main__": From 38eafd93ff4198997ac682066a18573375b8ee65 Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Thu, 14 Oct 2021 18:30:09 +0530 Subject: [PATCH 27/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index ec213e8a6002..4fb9f2eb6064 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -33,7 +33,7 @@ " ": " ", } -decode_dict = {value : key for key, value in encode_dict.items()} +decode_dict = {value: key for key, value in encode_dict.items()} def encode(word: str) -> str: @@ -69,7 +69,7 @@ def decode(coded: str) -> str: >>> encode("AABBBAABAAABABAABABAABBAB BABAAABBABBAAAAABABAAAABB!") Traceback (most recent call last): ... - Exception: encode() accepts only alphabets + Exception: decode() accepts only alphabets 'A', 'B' and spaces """ if set(coded) - {"A", "B", " "} != set() and set(coded) - {"A", "B"} != set(): raise Exception("decode accepts only 'A', 'B' and ' '") From 79ff3ef905d5350b80b4afc7cabeb15f2c5871d7 Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Thu, 14 Oct 2021 18:34:25 +0530 Subject: [PATCH 28/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 4fb9f2eb6064..8a48e9502364 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -73,7 +73,7 @@ def decode(coded: str) -> str: """ if set(coded) - {"A", "B", " "} != set() and set(coded) - {"A", "B"} != set(): raise Exception("decode accepts only 'A', 'B' and ' '") - decoded = "" + decoded = "" for word in coded.split(): while len(word) != 0: decoded += decode_dict[word[:5]] From 92e8b9e1df965f8597f03593fd637289103ca24f Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Thu, 14 Oct 2021 18:49:41 +0530 Subject: [PATCH 29/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 8a48e9502364..84f2278c3a1f 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -33,8 +33,6 @@ " ": " ", } -decode_dict = {value: key for key, value in encode_dict.items()} - def encode(word: str) -> str: """ From 42043bebf059d0ce1460390614844a536e5f170d Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Thu, 14 Oct 2021 18:54:45 +0530 Subject: [PATCH 30/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 84f2278c3a1f..a93797203c6e 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -70,7 +70,7 @@ def decode(coded: str) -> str: Exception: decode() accepts only alphabets 'A', 'B' and spaces """ if set(coded) - {"A", "B", " "} != set() and set(coded) - {"A", "B"} != set(): - raise Exception("decode accepts only 'A', 'B' and ' '") + raise Exception("decode accepts only alphabets 'A', 'B' and spaces") decoded = "" for word in coded.split(): while len(word) != 0: From 7a973dce0b5012a5cc8e4fcba340cdc4590c5389 Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Thu, 14 Oct 2021 19:05:02 +0530 Subject: [PATCH 31/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index a93797203c6e..559f525534a4 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -34,6 +34,9 @@ } +decode_dict = {value: key for key, value in encode_dict.items()} + + def encode(word: str) -> str: """ Encodes to Baconian cipher @@ -70,7 +73,7 @@ def decode(coded: str) -> str: Exception: decode() accepts only alphabets 'A', 'B' and spaces """ if set(coded) - {"A", "B", " "} != set() and set(coded) - {"A", "B"} != set(): - raise Exception("decode accepts only alphabets 'A', 'B' and spaces") + raise Exception("decode accepts only 'A', 'B' and ' '") decoded = "" for word in coded.split(): while len(word) != 0: @@ -82,5 +85,5 @@ def decode(coded: str) -> str: if "__name__" == "__main__": from doctest import testmod - + testmod() From 369e47bef1f929f0c35c2386356f92faa4abe7a1 Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Thu, 14 Oct 2021 19:11:46 +0530 Subject: [PATCH 32/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index 559f525534a4..a153a5b177db 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -73,7 +73,7 @@ def decode(coded: str) -> str: Exception: decode() accepts only alphabets 'A', 'B' and spaces """ if set(coded) - {"A", "B", " "} != set() and set(coded) - {"A", "B"} != set(): - raise Exception("decode accepts only 'A', 'B' and ' '") + raise Exception("decode() accepts only 'A', 'B' and spaces") decoded = "" for word in coded.split(): while len(word) != 0: @@ -85,5 +85,5 @@ def decode(coded: str) -> str: if "__name__" == "__main__": from doctest import testmod - + testmod() From a4cf59c77ad851e3a8cc5be435c2d65a97024f21 Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Thu, 14 Oct 2021 19:21:27 +0530 Subject: [PATCH 33/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index a153a5b177db..d740bf7a6c15 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -67,7 +67,7 @@ def decode(coded: str) -> str: 'hello world' >>> decode("AABBBAABAAABABAABABAABBAB") 'hello' - >>> encode("AABBBAABAAABABAABABAABBAB BABAAABBABBAAAAABABAAAABB!") + >>> decode("AABBBAABAAABABAABABAABBAB BABAAABBABBAAAAABABAAAABB!") Traceback (most recent call last): ... Exception: decode() accepts only alphabets 'A', 'B' and spaces From 694cb87a4938bf74ce5a8977000bbc01796bd620 Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Thu, 14 Oct 2021 19:27:24 +0530 Subject: [PATCH 34/34] Update baconian_cipher.py --- ciphers/baconian_cipher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/baconian_cipher.py b/ciphers/baconian_cipher.py index d740bf7a6c15..027fbc50e89d 100644 --- a/ciphers/baconian_cipher.py +++ b/ciphers/baconian_cipher.py @@ -70,9 +70,9 @@ def decode(coded: str) -> str: >>> decode("AABBBAABAAABABAABABAABBAB BABAAABBABBAAAAABABAAAABB!") Traceback (most recent call last): ... - Exception: decode() accepts only alphabets 'A', 'B' and spaces + Exception: decode() accepts only 'A', 'B' and spaces """ - if set(coded) - {"A", "B", " "} != set() and set(coded) - {"A", "B"} != set(): + if set(coded) - {"A", "B", " "} != set(): raise Exception("decode() accepts only 'A', 'B' and spaces") decoded = "" for word in coded.split():