28 lines
664 B
Python
28 lines
664 B
Python
#!/usr/bin/env python
|
|
import json
|
|
import sys
|
|
|
|
alphabet = 'abcdefghijklmnopqrstuvwxyz*'
|
|
|
|
srcpath = sys.argv[1]
|
|
targetpath = sys.argv[2]
|
|
|
|
with open(srcpath, 'r') as f:
|
|
words = json.load(f)
|
|
|
|
# We only care about 5-letter words
|
|
words = [word for word in words if len(word) == 5]
|
|
|
|
array = []
|
|
for word in words:
|
|
number = 0
|
|
for index, letter in enumerate(word):
|
|
number += alphabet.index(letter) << (5 * index)
|
|
packed = bytes([number & 0xff, (number >> 8) & 0xff, (number >> 16) & 0xff, number >> 24])
|
|
array.append(packed)
|
|
|
|
with open(targetpath, 'w') as f:
|
|
f.write('targets:\n')
|
|
for packed in array:
|
|
f.write(f'\tdb {", ".join(str(byte) for byte in packed)}\n')
|