MITx and the Python DUDE .: This week the focus was on Python classes and inheritance in the context of object-oriented programming. Objects are a combination of data collections and the methods that operate on that data. It allows the programmer to move beyond the built-in types provided by Python (integers, floating point numbers, strings, lists, dictionaries) and roll their own purpose-built types with methods (which is very cool)!
I am still wrapping my head around the idea but I watched all the lecture videos and completed all the exercises for the week. The problem set involved creating a Python class + methods for encryption and decryption using the Caesar Cipher ...
The idea of the Caesar Cipher is to pick an integer and shift every letter of your message by that integer. In other words, suppose the shift is k . Then, all instances of the i-th letter of the alphabet that appear in the plaintext should become the (i+k)-th letter of the alphabet in the ciphertext. You will need to be careful with the case in which i + k > 26 (the length of the alphabet). Here is what the whole alphabet looks like shifted three spots to the right:
Original: a b c d e f g h i j k l m n o p q r s t u v w x y z
3-shift: d e f g h i j k l m n o p q r s t u v w x y z a b c
Using the above key, we can quickly translate the message "happy" to "kdssb" (note how the 3-shifted alphabet wraps around at the end, so x -> a, y -> b, and z -> c).
The problem template provided a Message class and a few helper methods and I had to create new objects and methods to generate dictionaries to encrypt and decrypt plaintext messages. It (eventually) works!