diff --git a/README.md b/README.md index 65edb23..326326b 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,8 @@ the following rules: 1. The text is converted into lowercase. 2. Every occurrence of the `0` (zero) character is replaced with the letter `o`. 3. Every occurrence of either of these characters `_-` is replaced with a space. -4. Any other characters not belonging to the alphabet are deleted from the text. +4. Optionally, every newline is replaced with three consequent spaces. +5. Any other characters not belonging to the alphabet are deleted from the text. Prior to step 4, the user may apply additional conversions to preserve special characters, such as replacing `%` with `cto`, `$` with `dlr` and so on. diff --git a/ip36.py b/ip36.py index de98ad4..202d608 100755 --- a/ip36.py +++ b/ip36.py @@ -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