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:
@ -0,0 +1,19 @@
|
||||
from passgeny import bhash, phogen_map
|
||||
|
||||
def encode(bh: bhash.Bhash, ph_len: int):
|
||||
"""
|
||||
Consume the Bhash and return a string of length ph_len
|
||||
|
||||
This function generates a phonetic representation of the binary data in
|
||||
Bhash.
|
||||
"""
|
||||
phogen = ''
|
||||
ngram = ' '
|
||||
for x in range(ph_len):
|
||||
ngram_space = phogen_map.g_phonetic_map[ngram]
|
||||
n = bh.modulo(len(ngram_space))
|
||||
letter = ngram_space[n]
|
||||
ngram = ngram[1:] + letter
|
||||
phogen += letter
|
||||
|
||||
return phogen
|
||||
|
||||
Reference in New Issue
Block a user