diff --git a/README.md b/README.md index 326326b..b6dfcaa 100644 --- a/README.md +++ b/README.md @@ -163,10 +163,14 @@ After all plaintext characters are processed, add PL random characters in front of the ciphertext, where PL = KL mod 10 + 1, where KL is the initial key phrase length. None of the prepended characters must be a whitespace. +As the final step, replace all occurrences of double whitespace with `__` in +order to make sure the whitespace is transmitted correctly. + Decryption ---------- Remove first PL characters from the ciphertext, where PL = KL mod 10 + 1, where -KL is the initial key phrase length. +KL is the initial key phrase length. Also, replace all `__` occurrences with +double whitespaces. Then, for each ciphertext digraph C1C2, do the following: diff --git a/ip36.py b/ip36.py index 202d608..4215224 100755 --- a/ip36.py +++ b/ip36.py @@ -91,7 +91,7 @@ def ipfencrypt(msg:str, key:str): prefix = '' for i in range(preflen): prefix += secrets.choice(pfgrid[1:]) - return prefix + ''.join(enc) + return prefix + ''.join(enc).replace(' ', '__') # Interleaved Playfair decryption method def ipfdecrypt(enc:str, key:str): @@ -99,7 +99,7 @@ def ipfdecrypt(enc:str, key:str): # remove the prefix, then add a space if the cryptogram # had been stripped and ended with a space preflen = (len(key) % 10) + 1 - enc = enc[preflen:].rstrip() + enc = enc[preflen:].rstrip().replace('__', ' ') if len(enc) & 1 == 1: enc += ' ' # split into digraphs