python: Implement phogen encode
Implement phogen.encode() to encode Bhashes to phogen strings. This commit also adds unit tests for the above function.
This commit is contained in:
@ -9,8 +9,11 @@ test('test_phogen_map',
|
||||
'PHOGEN_MAP_PY=@0@'.format(_phogen_map_py),
|
||||
'PHOGEN_WORD_LIST=@0@'.format(_word_list)])
|
||||
|
||||
test('test_bhash',
|
||||
test('test_bhash_py',
|
||||
find_program('test_bhash.py'),
|
||||
env: ['SOURCE_ROOT=' + meson.project_source_root(),
|
||||
'PYTHONPATH=' + PYTHONPATH])
|
||||
env: ['PYTHONPATH=' + PYTHONPATH])
|
||||
|
||||
test('test_phogen_py',
|
||||
find_program('test_phogen.py'),
|
||||
env: ['PYTHONPATH=' + PYTHONPATH])
|
||||
|
||||
|
||||
27
tests/test_phogen.py
Executable file
27
tests/test_phogen.py
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
import hashlib
|
||||
|
||||
from passgeny import phogen
|
||||
from passgeny import bhash
|
||||
|
||||
PHO_GEN_TEST = [
|
||||
[ b"passgeny", "herang xiasem zitend qibele" ],
|
||||
[ b"phonetic", "lineum foneum zybale mangur" ],
|
||||
[ b"generator", "latole elitab ackina exprou" ],
|
||||
[ b"password", "nulize nomere fonici crednt" ],
|
||||
[ b"duck", "catabb rompor cricin prunsi" ] ]
|
||||
|
||||
for pt in PHO_GEN_TEST:
|
||||
bh = bhash.Bhash()
|
||||
bh.from_bytes(hashlib.sha256(pt[0]).digest())
|
||||
wa = []
|
||||
|
||||
for x in range(4):
|
||||
wa.append(phogen.encode(bh, 6))
|
||||
|
||||
word = " ".join(wa)
|
||||
|
||||
if word != pt[1]:
|
||||
raise Exception("Test failed: {} != {}".format(word, pt1))
|
||||
|
||||
print(word)
|
||||
Reference in New Issue
Block a user