-
Notifications
You must be signed in to change notification settings - Fork 1
/
crypt.py
55 lines (45 loc) · 1.48 KB
/
crypt.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
from Alphas import core
def freqal(text):
"""
crypt.freqal(text) -> dict
Returns a dictionary with alphabets as keys and their occurrence in the text
as the value.
"""
text = text.lower()
extra = '1234567890~`!@#$%^&*()-=_+|}{[]:\";\'\\<>,.?/ '
for i in extra:
text = text.replace(i, '')
freq = core.dic(0)
for i in text:
freq[i] += 1
return freq
def rot(rotv=13, start=0, end=26):
"""
crypt.rot([rotv, [start, [end]]]) -> dict
Returns a dictionary of alphabets (key is lowercase alphabet and value is
rotated alphabet) from start till end. Rot value is by default 13, but can
be anything. By default the start is 0 and end is 26.
"""
d = {}
for a in core.alist(start, end):
if (rotv + start < 26):
d[a] = core.alph(start+rotv,start+rotv+1)
else :
d[a] = core.alph(start+rotv-26,start+rotv-26+1)
start += 1
return d
def urot(rotv=13, start=0, end=26):
"""
crypt.urot([rotv, [start, [end]]]) -> dict
Returns a dictionary of alphabets (key is uppercase alphabet and value is
rotated alphabet) from start till end. Rot value is by default 13, but can
be anything. By default the start is 0 and end is 26.
"""
d = {}
for a in core.ualist(start, end):
if (rotv + start < 26):
d[a] = core.ualph(start+rotv,start+rotv+1)
else :
d[a] = core.ualph(start+rotv-26,start+rotv-26+1)
start += 1
return d