added double whitespace behaviour notion
This commit is contained in:
@@ -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
|
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.
|
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
|
Decryption
|
||||||
----------
|
----------
|
||||||
Remove first PL characters from the ciphertext, where PL = KL mod 10 + 1, where
|
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:
|
Then, for each ciphertext digraph C1C2, do the following:
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ def ipfencrypt(msg:str, key:str):
|
|||||||
prefix = ''
|
prefix = ''
|
||||||
for i in range(preflen):
|
for i in range(preflen):
|
||||||
prefix += secrets.choice(pfgrid[1:])
|
prefix += secrets.choice(pfgrid[1:])
|
||||||
return prefix + ''.join(enc)
|
return prefix + ''.join(enc).replace(' ', '__')
|
||||||
|
|
||||||
# Interleaved Playfair decryption method
|
# Interleaved Playfair decryption method
|
||||||
def ipfdecrypt(enc:str, key:str):
|
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
|
# remove the prefix, then add a space if the cryptogram
|
||||||
# had been stripped and ended with a space
|
# had been stripped and ended with a space
|
||||||
preflen = (len(key) % 10) + 1
|
preflen = (len(key) % 10) + 1
|
||||||
enc = enc[preflen:].rstrip()
|
enc = enc[preflen:].rstrip().replace('__', ' ')
|
||||||
if len(enc) & 1 == 1:
|
if len(enc) & 1 == 1:
|
||||||
enc += ' '
|
enc += ' '
|
||||||
# split into digraphs
|
# split into digraphs
|
||||||
|
|||||||
Reference in New Issue
Block a user