-
Notifications
You must be signed in to change notification settings - Fork 1
/
6.13.py
76 lines (62 loc) · 1.72 KB
/
6.13.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
COMP.CS.100 Week Chapter
Name: Shamsur Raza Chowdhury <shamsurraza.chowdhury@tuni.fi>
Student Number: 050359798
This program
"""
def read_message():
"""
this function reads message
"""
x=""
y=[]
while True:
x = input()
if x=="":
break
else:
y.append(x)
return y
def encrypt(string):
"""
Encrypts its parameter using ROT13 encryption technology.
:param text: str, string to be encrypted
:return: str, <text> parameter encrypted using ROT13
"""
x=""
regular_chars = ["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"]
encrypted_chars = ["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"]
if string.isupper():
stringLower = string.lower()
for i in range(0,26):
if stringLower==regular_chars[i]:
x = encrypted_chars[i].upper()
else:
for i in range(0,26):
if string==regular_chars[i]:
x = encrypted_chars[i]
if x== "":
return string
else:
return x
def row_encryption(string):
"""
this function perfoms a ROT13 transformation for an entire string
"""
x=""
for val in string:
x+= encrypt(val)
return x
def main():
print("Enter text rows to the message. Quit by entering an empty row.")
msg = read_message()
print("ROT13:")
for val in msg:
y=row_encryption(val)
print(y)
if __name__ == "__main__":
main()