src.ch06 package¶
Submodules¶
src.ch06.c1_invisible_ink_mono module¶
Use stenography to hide messages in a word processor document.
Use docx.Document
to hide encrypted messages in a word processor
document by embedding the encrypted message in a fake message’s whitespace,
then changing the encrypted message’s font color to white.
Note
Using LibreOffice version 6.0.7.3
Warning
There are many ways this method of stenography can fail. Please don’t use for actual covert operations (covered in MIT License).
-
src.ch06.c1_invisible_ink_mono.
check_fit
(plaintext: list, ciphertext: list) → int[source]¶ Check if ciphertext can fit in plaintext’s whitespace.
Sum number of blanks in plaintext and compare to number of characters in ciphertext to see if it can fit.
- Parameters
plaintext (list) – Paragraphs of a fake message in a list of strings (likely from
get_text()
).ciphertext (list) – Paragraphs of an encrypted message in a list of strings (likely from
get_text()
).
- Returns
Integer representing the number of needed blanks to fit ciphertext in plaintext.
0
would mean that ciphertext can fit in plaintext.
Note
To separate words, the blanks in ciphertext count toward the needed length of plaintext. By contrast, blank lines in plaintext do not count.
-
src.ch06.c1_invisible_ink_mono.
main
(fakefile: str = None, cipherfile: str = None, savepath: str = None) → None[source]¶ Demonstrate the invisible ink writer.
Demonstrate
write_invisible()
, but for testing, it is a basic wrapper function forwrite_invisible()
. Embed cipherfile in fakefile’s whitespace.- Parameters
- Returns
None
. The contents of cipherfile’s text is embedded in fakefile’s whitespace and saved to savepath.
-
src.ch06.c1_invisible_ink_mono.
write_invisible
(plaintext: list, ciphertext: list, template_path: str = None, filename: str = 'output.docx') → None[source]¶ Embed ciphertext in plaintext’s letter whitespace.
Open a template file, template_path, with the needed fonts, styles, and margins. Write each line in plaintext to the template file and add each line in ciphertext to plaintext’s space between letters by using a monospace font. Save the new file as filename.
- Parameters
plaintext (list) – Lines of a fake message in a list of strings (likely from
get_text()
).ciphertext (list) – Lines of an encrypted message in a list of strings (likely from
get_text()
).template_path (str) – Absolute path to .docx file with predefined fonts, styles, and margins. Defaults to
None
. If not provided, defaults will be created.filename (str) – File name to use for output file. Defaults to
output.docx
.
- Returns
None
. plaintext is written to the file at template_path with ciphertext embedded in the blank space.- Raises
ValueError – If the number of spaces in plaintext aren’t enough to embed ciphertext based on output of
check_fit()
.
Note
As of python-docx v0.8.10, creating custom styles isn’t well supported. More info here.
As a result, if a template isn’t provided, the default template is modified to use a font named
Courier New
on Windows andLiberation Mono
on other operating systems in theNormal
style.
src.ch06.p1_invisible_ink module¶
Use stenography to hide messages in a word processor document.
Use docx.Document
to hide encrypted messages in a word processor
document by embedding the encrypted message in a fake message’s whitespace,
then changing the encrypted message’s font color to white.
Note
Using LibreOffice version 6.0.7.3
Warning
There are many ways this method of stenography can fail. Please don’t use for actual covert operations (covered in MIT License).
-
src.ch06.p1_invisible_ink.
check_blanks
(plaintext: list, ciphertext: list) → int[source]¶ Check if the ciphertext can fit in plaintext.
Compare the number of blank lines in plaintext to the number of lines in ciphertext. If they aren’t a match, returns the number of extra blank lines needed.
- Parameters
plaintext (list) – Paragraphs of a fake message in a list of strings (likely from
get_text()
).ciphertext (list) – Paragraphs of an encrypted message in a list of strings (likely from
get_text()
).
- Returns
Integer representing the number of needed blank lines to fit ciphertext in plaintext.
0
would mean that ciphertext can fit in plaintext.
-
src.ch06.p1_invisible_ink.
get_text
(file_path: str, skip_blank: bool = True) → list[source]¶ Get text from a docx file.
Loads paragraphs from the given docx file into a list. Optionally skips blank lines.
- Parameters
- Returns
Each paragraph in the docx file in a list of strings.
Note
Does not copy formatting from docx file - only text.
-
src.ch06.p1_invisible_ink.
main
(fakefile: str = None, cipherfile: str = None, savepath: str = None) → None[source]¶ Demonstrate the invisible ink writer.
Demonstrate
write_invisible()
, but for testing, it is a basic wrapper function forwrite_invisible()
. Embed cipherfile in fakefile’s whitespace.- Parameters
- Returns
None
. The contents of cipherfile’s text is embedded in fakefile’s whitespace and saved to savepath.
-
src.ch06.p1_invisible_ink.
write_invisible
(plaintext: list, ciphertext: list, template_path: str = None, filename: str = 'output.docx') → None[source]¶ Embed ciphertext in plaintext’s whitespace.
Open a template file, template_path, with the needed fonts, styles, and margins. Write each paragraph in plaintext to the template file and add each paragraph in ciphertext to plaintext’s blank space. Save the new file as filename.
- Parameters
plaintext (list) – Paragraphs of a fake message in a list of strings (likely from
get_text()
).ciphertext (list) – Paragraphs of an encrypted message in a list of strings (likely from
get_text()
).template_path (str) – Absolute path to .docx file with predefined fonts, styles, and margins. Defaults to
None
. If not provided, defaults will be created.filename (str) – File name to use for output file. Defaults to
output.docx
.
- Returns
None
. plaintext is written to the file at template_path with ciphertext embedded in the blank space.- Raises
ValueError – If the number of blank lines in plaintext aren’t enough to embed ciphertext based on output of
check_blanks()
.
Note
As of python-docx v0.8.10, creating custom styles isn’t well supported. More info here.
As a result, if a template isn’t provided, the default template is used.
Module contents¶
Chapter 6.