Skip to content

Commit 667e65d

Browse files
author
Atul Kushwaha
committed
Create caesar_cipher.py
1 parent 44b3fe6 commit 667e65d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

caesar_cipher.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
print(r"""
2+
██████╗ █████╗ ███████╗███████╗ █████╗ ██████╗ ██████╗██╗██████╗ ██╗ ██╗███████╗██████╗
3+
██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗██╔══██╗ ██╔════╝██║██╔══██╗██║ ██║██╔════╝██╔══██╗
4+
██║ ███████║█████╗ ███████╗███████║██████╔╝ ██║ ██║██████╔╝███████║█████╗ ██████╔╝
5+
██║ ██╔══██║██╔══╝ ╚════██║██╔══██║██╔══██╗ ██║ ██║██╔═══╝ ██╔══██║██╔══╝ ██╔══██╗
6+
╚██████╗██║ ██║███████╗███████║██║ ██║██║ ██║ ╚██████╗██║██║ ██║ ██║███████╗██║ ██║
7+
╚═════╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
8+
9+
""")
10+
#caesar cipher encryption
11+
alphabets = ['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']
12+
encode = input("enter txt to be encrypted: ").replace(" ","").casefold()
13+
shift = int(input("how many character would you like to shift: "))
14+
encrypted_r =""
15+
encrypted_l =""
16+
for i in encode:
17+
index_r = (alphabets.index(i)+shift)%26
18+
encrypted_r += alphabets[index_r]
19+
index_l = (alphabets.index(i)-shift)%26
20+
encrypted_l += alphabets[index_l]
21+
print("{} when shifted {} character form right: {}".format(encode,shift,encrypted_r))
22+
print("{} when shifted {} character form left: {}".format(encode,shift,encrypted_l))
23+
24+
#caesar cipher decryption
25+
decode = input("enter caesar cipher encoded text: ").replace(" ","").casefold()
26+
Shift = int(input("how may characters where shifted: "))
27+
print("if shift was from left enter : l")
28+
print("if shift was from right enter : r")
29+
left_or_right = input("wether shift was from left or right: ").replace(" ","").casefold()
30+
decrypted_r =" "
31+
decrypted_l=" "
32+
for k in decode:
33+
Index_r = (alphabets.index(k) - Shift) % 26
34+
decrypted_r += alphabets[Index_r]
35+
Index_l= (alphabets.index(k) + Shift) % 26
36+
decrypted_l += alphabets[Index_l]
37+
if left_or_right == "l":
38+
print("{} when shifted {} character form left: {}".format(decode,shift,decrypted_l))
39+
elif left_or_right== "r":
40+
print("{} when shifted {} character form right: {}".format(decode,shift,decrypted_r))
41+
42+
43+
44+
45+
46+
47+
48+
49+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy