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 ...
Get Python Programming in Context, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.