added newline encoding logic
This commit is contained in:
@@ -20,7 +20,7 @@ pfsize = int(math.sqrt(len(pfgrid)))
|
||||
|
||||
# message/keystring preparation step: replace 0 with o then filter out all invalid chars
|
||||
def filtermsg(msg:str):
|
||||
return ''.join(list(filter(lambda i: i in pfgrid, msg.lower().replace('0', 'o'))))
|
||||
return ''.join(list(filter(lambda i: i in pfgrid, msg.lower().replace('0', 'o').replace('\n', ' '))))
|
||||
|
||||
# grid keying algorithm
|
||||
def keygrid(key:str):
|
||||
@@ -122,7 +122,7 @@ def ipfdecrypt(enc:str, key:str):
|
||||
x2 += pfsize
|
||||
msg.append(getgridchar(kg, x2, y2))
|
||||
# finalize the decrypted message
|
||||
return ''.join(msg).strip()
|
||||
return ''.join(msg).replace(' ', '\n').strip()
|
||||
|
||||
# entrypoint parameters: [mode] [keystring]
|
||||
# modes: e - encrypt with 6x6 IPF, d - decrypt with 6x6 IPF
|
||||
|
||||
Reference in New Issue
Block a user