-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_hex_words.py
More file actions
executable file
·56 lines (45 loc) · 1.32 KB
/
get_hex_words.py
File metadata and controls
executable file
·56 lines (45 loc) · 1.32 KB
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
#!/usr/bin/env python3
import sys
import json
DIGITS = {'O': '0', 'L': 'l', 'S': '5', # RE -faster?
'A': 'A', 'B': 'B', 'C': 'C', 'D': 'D', 'E': 'E', 'F': 'F'}
def convertible(some_word):
for char in some_word:
if char not in DIGITS:
return False
return True
def to_hex(some_word):
as_hex = ""
for char in some_word:
as_hex += DIGITS[char]
return as_hex
def check(some_word):
if convertible(some_word):
print(some_word)
else:
print('Sorry!')
def main():
try:
with open('common_word_list.json', 'r') as wordin:
word_dict = json.load(wordin)
except IOError:
import os
mydir = os.path.dirname(sys.argv[0])
with open(os.path.join(mydir, 'common_word_list.json'), 'r') as wordin:
word_dict = json.load(wordin)
min_length = 4
if len(sys.argv) > 1:
min_length = int(sys.argv[1])
print("Searching {:,} common English words".format(len(word_dict)))
counter = 40
for word in word_dict:
if len(word) < min_length:
continue
uword = word.upper()
if convertible(uword):
print("{} => {}".format(word, to_hex(uword)))
counter -= 1
if counter <= 0:
break
if __name__ == '__main__':
main()