Skip to content

Commit 696e056

Browse files
committed
Student marks grading
2 parents d5e02d1 + 08a5234 commit 696e056

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Caesar_cipher.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
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']
2+
def encryption(plain_text,shift_key):
3+
cipher_text = ""
4+
for char in plain_text:
5+
if char in alphabet:
6+
position = alphabet.index(char)
7+
new_position = (position+shift_key)%26
8+
cipher_text += alphabet[new_position]
9+
else:
10+
cipher_text += char
11+
print(f"Here's is the text after encryption: {cipher_text}")
12+
13+
def decryption(cipher_text,shift_key):
14+
plain_text = ""
15+
for char in cipher_text:
16+
if char in alphabet:
17+
position = alphabet.index(char)
18+
new_position = (position-shift_key)%26
19+
plain_text += alphabet[new_position]
20+
else:
21+
plain_text += char
22+
print(f"Here's is the text after decryption: {plain_text}")
23+
24+
end_program = False
25+
while not end_program:
26+
what_to_do = input("Type 'encrypt' for encryption, type 'decrypt' for decryption:\n")
27+
text = input("Type your message:\n").lower()
28+
shift = int(input("Enter shift key:\n"))
29+
if what_to_do=="encrypt":
30+
encryption(plain_text=text, shift_key=shift)
31+
elif what_to_do=="decrypt":
32+
decryption(cipher_text=text, shift_key=shift)
33+
play_again = input("Type 'yes' to continue, type 'no' to exit.\n")
34+
if play_again == 'no':
35+
end_program = True
36+
print("Have a nice day! Bye..")

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Caesar Cipher Python
2+
Encryption and Decryption

0 commit comments

Comments
 (0)