In these posts I outline the contents of each project in my book Python For Kids For Dummies. If you have questions or comments about the project listed in the title post them here. Any improvements will also be listed here.
What’s in Project 7
Project 7 (Cryptopy) introduces dictionaries as a means of encoding text using a Caesar cipher. Along the way, you are introduced to the string module and the characters in string.printable. There is some discussion about escape sequences and examples of \n and \t are given. Since you don’t want to encrypt escape sequences the slicing operator is introduced in order to take string.printable and slice off the control characters. This becomes the character set that will be encoded.
An encryption dictionary is created and each of the characters in a test message are encrypted then joined using the join method of the empty string. I explain why this is better than adding one character after another to an existing string. I create a matching decryption function and decryption dictionary and test the round trip (plaintext-> ciphertext -> plaintext).
The project introduces file operations by reading a message from a file then writing the encrypted (or decrypted) message to another file. This is first done with the base file operations open and close, then the with keyword is introduced to make the housekeeping a little easier.
I demonstrate how to use your newly written encryption functions from the command line by importing the code from your own file – your own third party module! In order for this to work seamlessly you are introduced to the __name__ attribute and the if __name__ == “__main__”: construction.