aboutsummaryrefslogtreecommitdiff
path: root/Python/Beginner training/Caeser Cypher.py
diff options
context:
space:
mode:
authorSyndamia <kami02882@gmail.com>2019-08-01 14:39:57 +0300
committerSyndamia <kami02882@gmail.com>2019-08-01 14:39:57 +0300
commitdfd68eb97e71ffe1f693526ba3daddd4c9558ce5 (patch)
tree74652dbd3dbaf6ae56f8c957ab16b2aa13e23574 /Python/Beginner training/Caeser Cypher.py
parente173839c44257d0187bb2ec087124db6e2ecde99 (diff)
downloadSelf-learning-dfd68eb97e71ffe1f693526ba3daddd4c9558ce5.tar
Self-learning-dfd68eb97e71ffe1f693526ba3daddd4c9558ce5.tar.gz
Self-learning-dfd68eb97e71ffe1f693526ba3daddd4c9558ce5.zip
Did Caeser cypher task (karan/Projects) in Python
Diffstat (limited to 'Python/Beginner training/Caeser Cypher.py')
-rw-r--r--Python/Beginner training/Caeser Cypher.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Python/Beginner training/Caeser Cypher.py b/Python/Beginner training/Caeser Cypher.py
new file mode 100644
index 0000000..b951e39
--- /dev/null
+++ b/Python/Beginner training/Caeser Cypher.py
@@ -0,0 +1,32 @@
+lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
+upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
+
+while True:
+ key = abs(int(input("Type a key (0 - 26): ")))
+ while key > 26:
+ key -= 26
+
+ msg = input("Type a message: ")
+ decoded = [] ; encoded = []
+
+ for c in msg:
+ try:
+ decoded.append(lower[lower.index(c) - key])
+ encoded.append(lower[lower.index(c) + key])
+ except:
+ try:
+ decoded.append(upper[upper.index(c) - key])
+ encoded.append(upper[upper.index(c) + key])
+ except:
+ decoded.append(c)
+ encoded.append(c)
+
+ print(end="Decoded message: ")
+ for c in decoded:
+ print(end=c)
+ print()
+
+ print(end="Encoded message: ")
+ for c in encoded:
+ print(end=c)
+ print("\n") \ No newline at end of file