-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoder.py
46 lines (29 loc) · 922 Bytes
/
encoder.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
import random
mycode = {'a': 'b', 'b': 'c', 'c': 'd', 'd': 'e', 'e': 'f', 'f': 'g',
'g': 'h', 'h': 'i', 'i': 'j', 'j': 'k', 'k': 'k', 'l': 'm',
'm': 'n', 'n': 'o', 'o': 'p', 'p': 'q', 'q': 'r', 'r': 's',
's': 't', 't': 'u', 'u': 'v', 'v': 'w', 'w': 'x', 'x': 'y',
'y': 'z', 'z': ' ', ' ': "a"}
def swap(d):
key1, key2 = random.sample(list(d), 2)
e = d.copy()
e[key1], e[key2] = d[key2], d[key1]
return e
def ktov(l):
word = ""
for elt in l:
try:
value = mycode[(elt)]
word += str(value)
except:
continue
return word
for i in range(40):
mycode = swap(mycode)
message = input('Enter sentence to encrypt: ')
m = []
m.append(list(message.lower().rstrip()))
m = [item for sublist in m for item in sublist]
codedtext = ktov(m)
with open("code.txt", "w") as f:
f.write(codedtext)