-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar_cipher.py
More file actions
53 lines (36 loc) · 954 Bytes
/
caesar_cipher.py
File metadata and controls
53 lines (36 loc) · 954 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
def encryption(text,shift):
#shifting characters
filter = []
for char in text:
if char.isalpha():
if ord(char.upper())+shift <= ord("Z"):
filter.append(chr(ord(char.upper())+shift))
else:
filter.append(chr(ord(char.upper()) + shift - 26))
#placing it in block of 5
five_block=[]
count = 0
block = ""
for char in filter:
block+=char
count+=1
if count == 5:
five_block.append(block)
count=0
block=""
if block:
five_block.append(block)
#keepting 10 blocks in each line
output = ""
count =0
for char in five_block:
if count == 10:
output+="\n"
count=0
output+=char+" "
count+=1
print(output.strip())
text = sys.argv[1]
shift = int(sys.argv[2])
encryption(text,shift)