-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrequency.py
44 lines (42 loc) · 975 Bytes
/
frequency.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
dict = {};
dict['a'] = 0.08167
dict['b'] = 0.01492
dict['c'] = 0.02782
dict['d'] = 0.04253
dict['e'] = 0.12702
dict['f'] = 0.02228
dict['g'] = 0.02015
dict['h'] = 0.06094
dict['i'] = 0.06966
dict['j'] = 0.00153
dict['k'] = 0.00772
dict['l'] = 0.04025
dict['m'] = 0.02406
dict['n'] = 0.06749
dict['o'] = 0.07507
dict['p'] = 0.01929
dict['q'] = 0.00095
dict['r'] = 0.05987
dict['s'] = 0.06327
dict['t'] = 0.09056
dict['u'] = 0.02758
dict['v'] = 0.00978
dict['w'] = 0.02360
dict['x'] = 0.00150
dict['y'] = 0.01974
dict['z'] = 0.00074
def scoreof(decoded_bytes):
if len(decoded_bytes) == 0: return 0
count = 0
counts = {}
for char_byte in decoded_bytes:
char = chr(char_byte)
counts.setdefault(char, 0)
counts[char] += 1
count += 1
score = 0.0
for char in dict:
letter_count = counts.get(char, 0)
difference = abs((letter_count / count) - dict.get(char, 0.0))
score += difference
return score