-
Notifications
You must be signed in to change notification settings - Fork 0
/
monoalphabetic_testing_
150 lines (121 loc) · 3.72 KB
/
monoalphabetic_testing_
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 25 07:57:04 2018
@author: stemoutreach
"""
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 24 08:29:21 2018
@author: stemoutreach
"""
import os
os.chdir("/Users/stemoutreach/monoalpha/")
#handler=open("tom_sawyer.txt", 'r')
#handler=open("test_text.txt", 'r')
#handler=open("english.txt", 'r')
handler=open("problem3.txt", 'r')
text = handler.read()
handler=open("words_alpha.txt", 'r')
dic = handler.read()
word_list = dic.rstrip().split("\n")
handler=open("key.txt", 'r')
key = handler.read()
word_list = key.rstrip().split()
alpha_low = ['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']
alpha_cap = ['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']
#a_upper = ['E','T','A','I','O','H','N',
# 'S','R','D','L','U','W','Y',
# 'C','M','G','K','F','P','B',
# 'V','Q','X','J','Z']
#a_lower = ['e','t','a','i','o','h','n',
# 's','r','d','l','u','w','y',
# 'c','m','g','k','f','p','b',
# 'v','q','x','j','z']
#a_upper = ['E','T','A','O','I','N','S',
# 'H','R','D','L','C','U','M',
# 'W','F','G','Y','P','B','V',
# 'K','J','X','Q','Z']
#a_lower = ['e','t','a','o','i','n','s',
# 'h','r','d','l','c','u','m',
# 'w','f','g','y','p','b','v',
# 'k','j','x','q','z']
def let_cnt(t, a_one,a_two):
char_cnt = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for char in t:
for i in range(len(a_one)):
if(char == a_one[i]):
char_cnt[i] += 1
for i in range(len(a_two)):
if(char == a_two[i]):
char_cnt[i] += 1
return char_cnt
def sort_lower(c,a_one):
fake = []
new_freq_low = []
for i in range(len(a_one)):
m=c[0]
ao=a_one[0]
for j in range(len(a_one)-1):
if(c[j+1] > m):
m = c[j+1]
ao = a_one[j+1]
c.remove(m)
a_one.remove(ao)
fake.append(m)
new_freq_low.append(ao)
return new_freq_low
def sort_upper(c,a_two):
fake = []
new_freq_cap = []
for i in range(len(c)):
m=c[0]
at=a_two[0]
for j in range(len(c)-1):
if(c[j+1] > m):
m = c[j+1]
at = a_two[j+1]
c.remove(m)
a_two.remove(at)
fake.append(m)
new_freq_cap.append(at)
return new_freq_cap
def letter_switch(a_one, a_two, t, d_one, d_two):
new_text = []
for char in t:
for i in range(len(a_one)):
if(char == a_one[i]):
new_text.append(d_one[i])
break
elif(char == a_two[i]):
new_text.append(d_two[i])
break
else:
new_text.append(char)
new_text = ''.join(new_text)
return new_text
a_upper = key
a_lower = key
a_lower = a_lower.lower()
x = let_cnt(text,
alpha_low,
alpha_cap)
y = let_cnt(text,
alpha_low,
alpha_cap)
sort_alpha_low = sort_lower(x,
alpha_low)
sort_alpha_cap = sort_upper(y,
alpha_cap)
print(letter_switch(sort_alpha_low,
sort_alpha_cap,
text,
a_lower,
a_upper))