-
Notifications
You must be signed in to change notification settings - Fork 0
/
caeser.py
44 lines (34 loc) · 1.22 KB
/
caeser.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
import configparser
configParser = configparser.RawConfigParser()
configFilePath = r'config.txt'
configParser.read(configFilePath)
def encrypt(msg, step):
outText = []
cryptText = []
caps = ['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']
nocaps = ['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']
for letter in msg:
if letter in caps:
contents = caps.index(letter)
encrypt = (contents + step) % 26
cryptText.append(encrypt)
newLetter = caps[encrypt]
outText.append(newLetter)
elif letter in nocaps:
contents = nocaps.index(letter)
encrypt = (contents + step) % 26
cryptText.append(encrypt)
newLetter = nocaps[encrypt]
outText.append(newLetter)
return outText
letters = int(configParser.get('letters', 'l'))
word = configParser.get('letters', 'word')
output = encrypt(word, letters)
print("-------------------------")
print(output)
print("-------------------------")
with open('config.txt', 'r') as file:
data = file.readlines()
data[6] = 'output = ' + str(output) + '\n'
with open('config.txt', 'w') as file:
file.writelines( data )