-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatistics.py
35 lines (31 loc) · 869 Bytes
/
statistics.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
#Get cipher text statistics
def statistics(doc):
x = doc.readline()
print(doc.readline())
a = list(x)
sts = {}
for letter in a:
if letter in sts:
sts[letter] = sts[letter] + 1
else:
sts[letter] = 1
print(display(sts))
#Convert dictionary to string
def display(dictionary):
l = ""
for key in dictionary:
l += key + "->" + str(dictionary[key]) + ", "
return l
#Decypher cipher text
def replacement(cipher, rule):
replaced = ""
print("Replacement Rule -> ", display(rule))
with open(cipher) as doc:
line = str(doc.readline())
for key in rule:
if(key == " "):
replaced = line.replace(key, rule[key])
else:
replaced = replaced.replace(key, rule[key])
print(replaced)
return replaced