added double whitespace behaviour notion

This commit is contained in:
Luxferre
2025-03-04 21:47:28 +02:00
parent 7f8c63ebd9
commit 3c608583a8
2 changed files with 7 additions and 3 deletions
+5 -1
View File
@@ -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:
+2 -2
View File
@@ -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