-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar_cipher.py
More file actions
32 lines (19 loc) · 808 Bytes
/
caesar_cipher.py
File metadata and controls
32 lines (19 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def caesar_cipher_encrypt(plaintext, shift):
result = ''
for char in plaintext:
if char.isalpha():
is_upper = char.isupper()
char_code = ord(char)
shifted_code = (char_code - ord('A' if is_upper else 'a') + shift) % 26
encrypted_char = chr(shifted_code + ord('A' if is_upper else 'a'))
result += encrypted_char
else:
result += char
return result
def main():
plaintext = input("Enter the plaintext: ")
shift = int(input("Enter the shift value: "))
ciphertext = caesar_cipher_encrypt(plaintext, shift)
print("Encrypted text:", ciphertext)
if __name__ == "__main__":
main()