3.6 Creating a Key
The strength of the substitution cipher lies in the ability of two people to share a key. That is, both the sender and the receiver of the encrypted message must have access to the same key. That key must represent a scrambled version of the 26 letters of the alphabet plus a space. As a first approach, let’s write a Python function that returns a randomly scrambled version of the alphabet.
The main idea in this algorithm is that we want to randomly select one character from the alphabet to include in our key, and then to randomly select another character, and another, until we have selected all 27 characters in a random order. This seems pretty simple at first, but we must carefully keep track of the characters we have ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access