ciphers.playfair_cipher¶
https://en.wikipedia.org/wiki/Playfair_cipher#Description
The Playfair cipher was developed by Charles Wheatstone in 1854 It’s use was heavily promotedby Lord Playfair, hence its name
Some features of the Playfair cipher are:
It was the first literal diagram substitution cipher
It is a manual symmetric encryption technique
It is a multiple letter encryption cipher
The implementation in the code below encodes alphabets only. It removes spaces, special characters and numbers from the code.
Playfair is no longer used by military forces because of known insecurities and of the advent of automated encryption devices. This cipher is regarded as insecure since before World War I.
Functions¶
|
|
|
Decode the input string using the provided key. |
|
Encode the given plaintext using the Playfair cipher. |
|
|
|
Prepare the plaintext by up-casing it |
Module Contents¶
- ciphers.playfair_cipher.chunker(seq: collections.abc.Iterable[str], size: int) collections.abc.Generator[tuple[str, Ellipsis], None, None] ¶
- ciphers.playfair_cipher.decode(ciphertext: str, key: str) str ¶
Decode the input string using the provided key.
>>> decode("BMZFAZRZDH", "HAZARD") 'FIREHAZARD' >>> decode("HNBWBPQT", "AUTOMOBILE") 'DRIVINGX' >>> decode("SLYSSAQS", "CASTLE") 'ATXTACKX'
- ciphers.playfair_cipher.encode(plaintext: str, key: str) str ¶
Encode the given plaintext using the Playfair cipher. Takes the plaintext and the key as input and returns the encoded string.
>>> encode("Hello", "MONARCHY") 'CFSUPM' >>> encode("attack on the left flank", "EMERGENCY") 'DQZSBYFSDZFMFNLOHFDRSG' >>> encode("Sorry!", "SPECIAL") 'AVXETX' >>> encode("Number 1", "NUMBER") 'UMBENF' >>> encode("Photosynthesis!", "THE SUN") 'OEMHQHVCHESUKE'
- ciphers.playfair_cipher.generate_table(key: str) list[str] ¶
- ciphers.playfair_cipher.prepare_input(dirty: str) str ¶
Prepare the plaintext by up-casing it and separating repeated letters with X’s