-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialog.py
73 lines (62 loc) · 2.12 KB
/
dialog.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
def input_dialog():
print ('''input name of file with encrypted text like this: "name.txt"
otherwise 'encrypted.txt' file would be used''')
file_name = input()
# print ('''\nchoose your variant of input:
#1. message encrypted with a Polybius square (by digits)
#2. message encrypted with a symbolic alphabet''')
# variant = int(input())
variant=input_variant()
alphabet = input_alphabet()
try:
f = open(file_name)
except Exception:
f=open('encrypted.txt')
#crypt = f.read().decode("utf8").upper().replace('\n','')
crypt = f.read().upper().replace('\n','')
print ('your message is:')
print ('-'*len(crypt))
print (crypt)
print ('-'*len(crypt))
return ([crypt, variant, alphabet])
def print_table(freq, real_freq):
for tup in freq:
print('{0} -- {1}'.format(tup[0], real_freq[freq.index(tup)][0]))
def print_table_2(freq, real_freq):
print("cypt frequency | real frequency")
for tup in freq:
print('{0} -- {1} | {2} -- {3}'.format(tup[0], tup[1], real_freq[freq.index(tup)][0], real_freq[freq.index(tup)][1]))
def input_variant():
print ('''\nchoose your variant of input:
1. message encrypted with a Polybius square (by digits)
2. message encrypted with a symbolic alphabet''')
while True:
variant=input()
try:
return int(variant)
except Exception:
print('input number')
def input_alphabet():
print (u'''\nchoose alphabet of decrypted text:
cyrillic
1. cyrillic without seperators <- 32 chars
2. cyrillic with seperators <- 37 chars (currently unavailable)
latin
3. A|B|C|...|Z <- 26 chars
4. A|B|...|Z|_ <- 27 chars''')
while True:
variant=input()
try:
return int(variant)
except Exception:
print('input number')
def how_to_decrypt():
print('''choose how to swap letters:
1. replace all letters at once according to theoretical frequency table
2. replace letters one by one''')
while True:
variant=input()
try:
return int(variant)
except Exception:
print('input number')