-
Notifications
You must be signed in to change notification settings - Fork 2
/
optimized_alphabets.py
58 lines (41 loc) · 1.13 KB
/
optimized_alphabets.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
import string
def alphabet_from_string(string, complete=True):
alpha = []
# add chars from string
for c in string:
val = ord(c)
if val not in alpha:
alpha.append(val)
# add missing byte values
if complete:
for i in range(255, 0, -1):
if i not in alpha:
alpha.append(i)
return alpha
def default_alphabet():
"""
All the plain old byte values.
"""
return list(range(255, 0, -1))
def printable_ascii_alphabet():
"""
This is faster for printable ASCII data.
"""
return alphabet_from_string(string.printable)
def padding_alphabet(block_size):
"""
This is faster for the padding.
"""
return list(range(0, block_size))[::-1] + list(range(block_size, 256)) + [0]
def json_alphabet():
"""
This is faster for JSON data.
"""
alpha = ''
# JSON special characters
alpha += '{}[]": ,\\'
# alphanumeric
alpha += string.ascii_lowercase + string.digits + string.ascii_uppercase
# remaining printable ascii
alpha += string.printable
return alphabet_from_string(alpha)