Introduction
Book cipher
A Book cipher is a very unique method of a encipher. Here's how's it done:
- You have a book / a document or a article (something full of text, the more pages of text the better).
- You have a message to convey (a secret, of some sort)
- You simply-put read trough the text and the secret message (may come from input, or reading it from 2 separate files) - split it into words (so, separate spaces, commas and [dots]) so, ',' , '.' and spaces is the only requirement, how is not really that hugely important and you keep the count of how many words there are in the text, now input the secret message (note, the secret's words must be in the text, so if you secret was "My Secret" then, the words "My" and "Secrets" must both exist in the text.) and output the position of the inputted secret message. (E.g if the word "My" was nearly at the first page, maybe the 20th Word in the text, the program should print out '20'. Same with the word "Secrets", if that maybe were later, (let say the 93th word in the text) then your program should print out '93'.
Note the data type of input and output:
output numbers: Integers.
Input numbers: Integers
( Excluding if the secret actually contains a number, then it does not need to be treated as a int. Can be a plus if it does but is not necessary.)
Mini Example:
document.txt - file that contains text.
Secret: "My Secret"
(in the text, this is the 20th and the 93th word) (Note, this is only a made up secret, it is not from a real file, or a real input) a more better example is below.
Program input:
You enter "My Secret"
Program output:
20
93
And, again - you enter those numbers(**Integers**):
20 93
Program outputs:
My
Secret
this is just to show how input and outputs are related to each other.
For reference (if needed) You have a Python3 implementation available at my GitHub page, to see a book cipher in action here: GitHub - Book cipher in Py3
- Why is this challenge interesting?
I personally think this is a educational (and interesting) challenge ( one might also exercise, because of how simple it might seem to make, but really took myself - literally years to even know how to implement this correctly)
Interesting article to get some background of what Cicada3301 is (not my site) - https://www.clevcode.org/cicada-3301/
I created this challenge both to, see other peoples methods of solving this (you are free to use any programming language!) and also - how long it would take others (For me, really I think it took more than 4 years actually - even in Python3. It looks simple but, for me - really not)
- A motivating fact: There are still so little info (especially on example codes) on the internet(at least by the time writing this challenge) about just, book cipher implementations
Challenge
I would highly suggest making dedicated functions for this challenge
- (instead of writing all code in the main() function - but it's totally fine to have it all in main!)
Operation:
Here's how the program should read, process, and output the result:
First, take the text (the book/document, with the lots of text, (not the secret)) and:
Note: The text can either be entered or read from a file. You choose this.
- read it (From a file, or enter it as input)
- split it into words (by, I.e detecting '.', spaces(' '), and commas ',') (Or if you already have split the input & are ready to move on to step 3, do that :) )
- count the number of words.
Repeat this process with the Secret input part.
So, the input secret part should be:
- read it (from, again a file or enter it as input)
- split it (i.e if your input was "My Secret" - split it into words like so: "My" "Secret")
My Python3 implementation only separate spaces.
The Key sequence - this is the nth words your text contains, e.g the 93th word in above example "Secrets".
The winner will be chosen by how short the code is. (So, the shortest code = win)
Example Input and Output
example file used 'document1.txt'in this section is available at the GitHub page.
as well as the Python3 file used in the example below.
The output of your program should match the output of the Python3 program.
Input:
python3 bookcipher.py
input text: a house with a Bob inside
Output:
you entered these words: ['a', 'house', 'with', 'a', 'Bob', 'inside']
2
3
5
2
0
30
Input again: (decrypting)
input key-sequence sep. With spaces: 2 3 5 2 0 30
a
house
with
a
Bob
inside
,
,.
,` `, but the reference program uses python's string.split(), which splits on whitespace... which one should we do? \$\endgroup\$