From f1bdcfc2ab9a980d122e58fbc7c926afbaa8b033 Mon Sep 17 00:00:00 2001 From: LethargicLeprechaun Date: Wed, 29 Apr 2020 21:09:53 +0100 Subject: [PATCH 01/11] A1Z26 Cipher --- ciphers/a1z26.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ciphers/a1z26.py diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py new file mode 100644 index 000000000000..c86d97f4cfec --- /dev/null +++ b/ciphers/a1z26.py @@ -0,0 +1,22 @@ +def encode(plain): + result = [] + for elem in plain: + result.append(ord(elem) - 96) + return result + +def decode(encoded): + result = "" + for elem in encoded: + result += chr(elem + 96) + return result + +def main(): + inp = input("->") + lowered = inp.lower() + encoded = encode(lowered) + print("Encoded: ", encoded) + decoded = decode(encoded) + print("Decoded:", decoded) + +if __name__ == "__main__": + main() \ No newline at end of file From d1df4d6116dd89df543995119b669ab372d546f6 Mon Sep 17 00:00:00 2001 From: LethargicLeprechaun Date: Wed, 29 Apr 2020 21:16:18 +0100 Subject: [PATCH 02/11] A1Z26 Cipher --- ciphers/a1z26.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index c86d97f4cfec..0a155f8312a9 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -19,4 +19,4 @@ def main(): print("Decoded:", decoded) if __name__ == "__main__": - main() \ No newline at end of file + main() From aa4b4ad9c338eddcd66a328cc0bb35317ab11656 Mon Sep 17 00:00:00 2001 From: LethargicLeprechaun Date: Wed, 29 Apr 2020 21:20:34 +0100 Subject: [PATCH 03/11] Added type hints --- ciphers/a1z26.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index 0a155f8312a9..ff16429fe2c0 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -1,10 +1,10 @@ -def encode(plain): +def encode(plain : str) -> list: result = [] for elem in plain: result.append(ord(elem) - 96) return result -def decode(encoded): +def decode(encoded : list) -> str: result = "" for elem in encoded: result += chr(elem + 96) From d3bddb6f1cf64284df6aed69f2b1487d9af9da7f Mon Sep 17 00:00:00 2001 From: LethargicLeprechaun Date: Wed, 29 Apr 2020 21:28:42 +0100 Subject: [PATCH 04/11] Added Doctests --- ciphers/a1z26.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index ff16429fe2c0..85bd160b7216 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -1,10 +1,18 @@ def encode(plain : str) -> list: + """ + >>> encode("MyName") + Encoded: [13, 25, 14, 1, 13, 5] + """ result = [] for elem in plain: result.append(ord(elem) - 96) return result def decode(encoded : list) -> str: + """ + >>> decode([13, 25, 14, 1, 13, 5]) + Decoded: myname + """ result = "" for elem in encoded: result += chr(elem + 96) From 0d09165f765b483f75c574cb02b949872ff51f29 Mon Sep 17 00:00:00 2001 From: LethargicLeprechaun Date: Wed, 29 Apr 2020 21:34:38 +0100 Subject: [PATCH 05/11] removed tabs, spaces instead --- ciphers/a1z26.py | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index 85bd160b7216..a1a1b579382c 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -1,30 +1,30 @@ def encode(plain : str) -> list: - """ - >>> encode("MyName") - Encoded: [13, 25, 14, 1, 13, 5] - """ - result = [] - for elem in plain: - result.append(ord(elem) - 96) - return result + """ + >>> encode("MyName") + Encoded: [13, 25, 14, 1, 13, 5] + """ + result = [] + for elem in plain: + result.append(ord(elem) - 96) + return result def decode(encoded : list) -> str: - """ - >>> decode([13, 25, 14, 1, 13, 5]) - Decoded: myname - """ - result = "" - for elem in encoded: - result += chr(elem + 96) - return result + """ + >>> decode([13, 25, 14, 1, 13, 5]) + Decoded: myname + """ + result = "" + for elem in encoded: + result += chr(elem + 96) + return result def main(): - inp = input("->") - lowered = inp.lower() - encoded = encode(lowered) - print("Encoded: ", encoded) - decoded = decode(encoded) - print("Decoded:", decoded) + inp = input("->") + lowered = inp.lower() + encoded = encode(lowered) + print("Encoded: ", encoded) + decoded = decode(encoded) + print("Decoded:", decoded) if __name__ == "__main__": - main() + main() From a5a331cf5cae3ee25dc550a57392ab547f791697 Mon Sep 17 00:00:00 2001 From: LethargicLeprechaun Date: Wed, 29 Apr 2020 21:40:53 +0100 Subject: [PATCH 06/11] corrected doctest --- ciphers/a1z26.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index a1a1b579382c..d0dc0644fa08 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -1,7 +1,7 @@ def encode(plain : str) -> list: """ >>> encode("MyName") - Encoded: [13, 25, 14, 1, 13, 5] + [13, 25, 14, 1, 13, 5] """ result = [] for elem in plain: @@ -11,7 +11,7 @@ def encode(plain : str) -> list: def decode(encoded : list) -> str: """ >>> decode([13, 25, 14, 1, 13, 5]) - Decoded: myname + myname """ result = "" for elem in encoded: From be89cea5073b607e63450ba776387ad854531b66 Mon Sep 17 00:00:00 2001 From: LethargicLeprechaun Date: Wed, 29 Apr 2020 21:47:08 +0100 Subject: [PATCH 07/11] corrected doctest --- ciphers/a1z26.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index d0dc0644fa08..acb4d6bdc171 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -1,6 +1,6 @@ def encode(plain : str) -> list: """ - >>> encode("MyName") + >>> encode("myname") [13, 25, 14, 1, 13, 5] """ result = [] @@ -11,7 +11,7 @@ def encode(plain : str) -> list: def decode(encoded : list) -> str: """ >>> decode([13, 25, 14, 1, 13, 5]) - myname + 'myname' """ result = "" for elem in encoded: From 5577c9f48bf7741c4dfba40ca16cfa438067cc7f Mon Sep 17 00:00:00 2001 From: LethargicLeprechaun Date: Wed, 29 Apr 2020 21:59:08 +0100 Subject: [PATCH 08/11] info URLs added --- ciphers/a1z26.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index acb4d6bdc171..8b8ed9dd1894 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -1,3 +1,12 @@ +""" + +Converts a string of characters to a sequence of numbers corresponding to the character's position in the alphabet. + +Information URLs: +https://www.dcode.fr/letter-number-cipher +http://bestcodes.weebly.com/a1z26.html +""" + def encode(plain : str) -> list: """ >>> encode("myname") From 6e756b5b13695a2e22c5d8d0c750aed1418661f7 Mon Sep 17 00:00:00 2001 From: LethargicLeprechaun Date: Wed, 29 Apr 2020 22:49:21 +0100 Subject: [PATCH 09/11] Condensed encode function to a single line --- ciphers/a1z26.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index 8b8ed9dd1894..6b0c4e19ccfa 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -12,10 +12,7 @@ def encode(plain : str) -> list: >>> encode("myname") [13, 25, 14, 1, 13, 5] """ - result = [] - for elem in plain: - result.append(ord(elem) - 96) - return result + return [ord(elem) - 96 for elem in plain] def decode(encoded : list) -> str: """ From 855004a6655e58b750a2b9009af808944925134f Mon Sep 17 00:00:00 2001 From: LethargicLeprechaun Date: Wed, 29 Apr 2020 22:39:56 +0100 Subject: [PATCH 10/11] Condensed decode to one line --- ciphers/a1z26.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index 6b0c4e19ccfa..d000e200ce4c 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -19,10 +19,7 @@ def decode(encoded : list) -> str: >>> decode([13, 25, 14, 1, 13, 5]) 'myname' """ - result = "" - for elem in encoded: - result += chr(elem + 96) - return result + return "".join(map(lambda elem : chr(elem + 96), encoded)) def main(): inp = input("->") From 6166e0cecfcdebb78537e95e370aae65105b7989 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 29 Apr 2020 23:58:01 +0200 Subject: [PATCH 11/11] Nice one! --- ciphers/a1z26.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index d000e200ce4c..3684c8cb3294 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -1,33 +1,29 @@ """ +Convert a string of characters to a sequence of numbers +corresponding to the character's position in the alphabet. -Converts a string of characters to a sequence of numbers corresponding to the character's position in the alphabet. - -Information URLs: https://www.dcode.fr/letter-number-cipher http://bestcodes.weebly.com/a1z26.html """ -def encode(plain : str) -> list: +def encode(plain: str) -> list: """ >>> encode("myname") [13, 25, 14, 1, 13, 5] """ return [ord(elem) - 96 for elem in plain] -def decode(encoded : list) -> str: +def decode(encoded: list) -> str: """ >>> decode([13, 25, 14, 1, 13, 5]) 'myname' """ - return "".join(map(lambda elem : chr(elem + 96), encoded)) + return "".join(chr(elem + 96) for elem in encoded) def main(): - inp = input("->") - lowered = inp.lower() - encoded = encode(lowered) + encoded = encode(input("->").strip().lower()) print("Encoded: ", encoded) - decoded = decode(encoded) - print("Decoded:", decoded) + print("Decoded:", decode(encoded)) if __name__ == "__main__": main()