src.ch04.challenge package¶
Submodules¶
src.ch04.challenge.c1_encode_route module¶
Encode a route cipher and replace code words.
-
src.ch04.challenge.c1_encode_route.
encode_route
(plaintext: str, keys: list, rows: int) → list[source]¶ Encode plaintext message with route cipher.
Clean plaintext with
format_plaintext()
, replace sensitive intel withreplace_words()
, fill with dummy words usingfill_dummy()
until keys and rows are factors, then encrypt with a route cipher using keys.- Parameters
- Returns
List of strings of transposed words.
Note
Assumes vertical encoding routes.
-
src.ch04.challenge.c1_encode_route.
fill_dummy
(plainlist: list, factors: list, dummy_words: list = None) → list[source]¶ Fill a plainlist with dummy words.
Adds pseudorandom dummy words to the end until the factors of the length of plainlist includes factors.
- Parameters
plainlist (list) – List of words of plaintext message.
factors (list) – List of integers that must be factors of the length of plainlist.
dummy_words (list) – List of dummy words to use as filler. If not provided, defaults to
DICTIONARY_FILE_PATH
usingcleanup_dict()
.
- Returns
Same list as plainlist, but with dummy words added.
-
src.ch04.challenge.c1_encode_route.
format_plaintext
(plaintext: str) → list[source]¶ Format plaintext message for encoding.
Prepare plaintext for route cipher encoding. Convert to lowercase, remove punctuation.
- Parameters
plaintext (str) – Plaintext message to format.
- Returns
List of strings of each word in plaintext message.
src.ch04.challenge.c2_encode_rail module¶
Encode message with a 3-rail fence cipher.
-
src.ch04.challenge.c2_encode_rail.
encode_rail
(plaintext: str, split: int = 5) → str[source]¶ Encode rail fence cipher.
Encode plaintext with a 3-rail fence cipher. Scrub the plaintext with
format_plaintext()
, then encrypt it withsplit_rails()
.
-
src.ch04.challenge.c2_encode_rail.
split_rails
(plaintext: str) → str[source]¶ Split plaintext into 3 rails for encryption.
Split the rails where the top rail is every 4th letter, the middle rail is every other letter starting at 1, and the bottom rail is every 4th letter starting at 2. After splitting, concatenate each rail and return the result.
- Parameters
plaintext (str) – Plain text message without spaces or punctuation.
- Returns
String with message encrypted using 3 rail fence cipher.
Module contents¶
Chapter 4 Challenge Projects.