Skip to content

Commit 2ce4465

Browse files
authored
Merge pull request #40 from Damsith-LK/main
Added Caeser Cipher
2 parents a4ba49f + e645182 commit 2ce4465

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

Caeser Cipher.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import string
2+
logo = """
3+
,adPPYba, ,adPPYYba, ,adPPYba, ,adPPYba, ,adPPYYba, 8b,dPPYba,
4+
a8" "" "" `Y8 a8P_____88 I8[ "" "" `Y8 88P' "Y8
5+
8b ,adPPPPP88 8PP""""""" `"Y8ba, ,adPPPPP88 88
6+
"8a, ,aa 88, ,88 "8b, ,aa aa ]8I 88, ,88 88
7+
`"Ybbd8"' `"8bbdP"Y8 `"Ybbd8"' `"YbbdP"' `"8bbdP"Y8 88
8+
88 88
9+
"" 88
10+
88
11+
,adPPYba, 88 8b,dPPYba, 88,dPPYba, ,adPPYba, 8b,dPPYba,
12+
a8" "" 88 88P' "8a 88P' "8a a8P_____88 88P' "Y8
13+
8b 88 88 d8 88 88 8PP""""""" 88
14+
"8a, ,aa 88 88b, ,a8" 88 88 "8b, ,aa 88
15+
`"Ybbd8"' 88 88`YbbdP"' 88 88 `"Ybbd8"' 88
16+
88
17+
88
18+
"""
19+
20+
print(logo)
21+
22+
alphabet = ['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', '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']
23+
24+
25+
def caesar(start_text, shift_amount, cipher_direction):
26+
end_text = ""
27+
if cipher_direction == "decode":
28+
shift_amount *= -1
29+
30+
for char in start_text:
31+
if char not in string.ascii_lowercase:
32+
end_text += char
33+
continue
34+
else:
35+
position = alphabet.index(char)
36+
new_position = position + shift_amount
37+
end_text += alphabet[new_position]
38+
39+
print(f"Here's the {cipher_direction}d result: {end_text}")
40+
41+
42+
while True:
43+
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
44+
text = input("Type your message:\n").lower()
45+
shift = int(input("Type the shift number:\n"))
46+
caesar(start_text=text, shift_amount=shift % 26, cipher_direction=direction)
47+
restart = input("Do you want to go again, type 'yes' or 'no':\n").lower()
48+
if restart == 'yes':
49+
pass
50+
else:
51+
break

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ I have listed some of the interesting python related topics and programs that I
5252
26. [Matrix_Multiplier](https://github.com/proPrateekSahu/Beginners-Python-Projects/blob/main/MatrixMultiplier.py) - [Prateek Kumar Sahu](https://github.com/proPrateekSahu)
5353
27. [Create Code To Find LCM](https://github.com/abhaypratapsinghkanpur/Beginners-Python-Projects/blob/main/Code%20To%20Find%20LCM) - [Abhay Pratap Singh](https://github.com/abhaypratapsinghkanpur)
5454
28. [Create Python Program to Find the Square Root.py](https://github.com/abhaypratapsinghkanpur/Beginners-Python-Projects/blob/main/Create%20Python%20Program%20to%20Find%20the%20Square%20Root.py) - [Abhay Pratap Singh](https://github.com/abhaypratapsinghkanpur)
55-
55+
29. [Caeser Cipher](https://github.com/Damsith-LK/Beginners-Python-Projects/blob/main/Caeser%20Cipher.py) - [Damsith Wijekoon](https://github.com/Damsith-LK)

0 commit comments

Comments
 (0)