aboutsummaryrefslogtreecommitdiff
path: root/Python/Beginner training
diff options
context:
space:
mode:
Diffstat (limited to 'Python/Beginner training')
-rw-r--r--Python/Beginner training/Caeser Cypher.py32
-rw-r--r--Python/Beginner training/Tasks.py22
2 files changed, 33 insertions, 21 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
diff --git a/Python/Beginner training/Tasks.py b/Python/Beginner training/Tasks.py
index d60a8bf..3ba4354 100644
--- a/Python/Beginner training/Tasks.py
+++ b/Python/Beginner training/Tasks.py
@@ -65,28 +65,8 @@ def Factoriel():
print(final_int)
-def CaesarCypher():
- while True:
- key = input("Type a key: ")
- msg = input("Type a message: ")
-
- decoded = [] ; encoded = []
- for c in msg:
- decoded.append(c - key)
- encoded.append(c + key)
-
- print(end="Decoded message: ")
- for c in decoded:
- print(end=c)
- print()
-
- print(end="Encoded message")
- for c in encoded:
- print(end=c)
-
#Divide()
#Histogram()
#NumberMatrix()
-#Factoriel()
-CaesarCypher() \ No newline at end of file
+#Factoriel() \ No newline at end of file