-
Notifications
You must be signed in to change notification settings - Fork 0
/
cypher.py
executable file
·108 lines (77 loc) · 2.29 KB
/
cypher.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python3
import string
import random
test = string.ascii_lowercase + string.digits
###this is sorta needed I guess###
extra = ' ' + '!' + '?' + ',' + '.' + '-' + '<' + '>' + '=' + "'" # added equal sign
letters = string.ascii_lowercase + extra
###/###
def randgen(seeed):
i = 0
random.seed(seeed)
thing = (list(test))
bleh = []
while i < len(letters):
fuck = (random.choice(thing))
if fuck not in bleh:
bleh.append(fuck)
final = ''.join(bleh)
i = i + 1
return final
seeed = input('choose seed')
randgen(seeed)
ranletters = randgen(seeed)
def encoder(sentence):
print('encoding...')
i = 0
x = 0
notalist = []
global encoding
encoding = {}
while i < len(ranletters):
encoding.update({letters[i]:ranletters[i]})
i += 1
while x < len(sentence):
splitsentence = encoding[sentence[x]]
notalist.append(splitsentence)
joinedsentence = ''.join(notalist)
x += 1
print("your encoded sentence is: " + joinedsentence)
def decoder(code):
print('decoding...')
i = 0
x = 0
notalist = []
letters = string.ascii_lowercase + extra
global decoding
decoding = {}
while i < len(ranletters):
decoding.update({ranletters[i]:letters[i]})
#print(decoding)
#sleep(1)
i += 1
while x < len(code):
try:
splitsentence = decoding[code[x]]
except:
print("Fatal Error!\nYou probably typed the code wrong or used the wrong seed.")
menu()
notalist.append(splitsentence)
joinedsentence = ''.join(notalist)
x += 1
print("your decoded sentence is: " + joinedsentence)
def menu():
while True:
option = input('What do you want to do? ')
if option.lower() in ('encode', 'encrypt', '1'):
sentence = input('What is your sentence? ').lower()
encoder(sentence)
elif option.lower() in ('decode', 'decrypt', '2'):
code = input('What is your code? ').lower()
decoder(code)
elif option.lower() in ('leave', 'exit', '3'):
print('Bye!')
quit()
else:
print('Please answer with either encode, decode, or leave. ')
menu()