Lecture 11: Cryptography
Watch on YouTube →
Overview
The lecture introduces cryptography through historical examples and Python implementations, moving from substitution ciphers and Caesar’s shift to Vigenère, public-key cryptography, and one-time pads. It demonstrates ASCII-based Caesar encryption with modulo 26, brute-force decryption of all 26 shifts, and key-based substitution, while explaining why weak ciphers can be attacked and why man-in-the-middle attacks remain a practical threat.
Key takeaways
- A Caesar cipher can be implemented by mapping lowercase letters to 0–25, adding or subtracting a shift, applying modulo 26, and converting back to ASCII with chr().
- Trying all 26 Caesar shifts in Python exposes the weakness of a tiny key space; the lecture's example recovers “Minnesota United Football Club” with shift 17.
- A Vigenère cipher repeats a keyword and combines each keyword letter with a plaintext letter, varying the shift across the message but still leaving repeated patterns that can aid analysis.
- RSA public-key cryptography, introduced in 1977 by Rivest, Shamir, and Adleman, relies on the computational difficulty of factoring products of large primes.
- A one-time pad can provide strong secrecy when its key is genuinely random and shared by both parties, but producing and distributing such keys is difficult.
- Man-in-the-middle attacks target trust and message delivery: an attacker may impersonate a recipient, relay traffic, and alter messages without directly cracking the encryption.
Chapters
- The exam is scheduled during each student's Lab 7 section between October 6 and October 12; taking it in another lab requires advance coordination.
- A practice exam and answer key were distributed, and the next class meeting is reserved for reviewing them.
- The exam is worth 100 points with 105 points available, and students may bring one handwritten or typed notes sheet in a size that does not disturb neighbors.
- The practice exam's second page contains useful notes and possible hints, and several questions closely correspond to exam questions.
- The instructor cautions against copying practice answers when they do not fit the specific exam question.
- For Lab 6, students choose either the more-comfortable or less-comfortable versions of the Mario and Cash or Credit assignments; they are not expected to complete all four.
- Cryptography creates ciphers, while cryptanalysis attempts to break them; plaintext is the original message and ciphertext is its transformed form.
- A cipher differs from speaking in code: a cipher makes text look like gibberish, while code hides meaning through shared context.
- The Enigma machine used configured rotors to encrypt German military messages, protecting troop movements and logistics from interception.
- A known plaintext example—such as recognizing the encrypted phrase as “Python rocks”—can provide a crib that helps reveal a substitution cipher.
- The Caesar cipher shifts each alphabet letter by a fixed number; encryption adds the shift and decryption subtracts it.
- A traditional shift of 3 gives only 25 useful nonzero rotations, making exhaustive manual checking feasible.
- ROT13 shifts letters by 13 and reverses itself when applied a second time, so it is sometimes used to obscure online spoilers.
- Python's ord() converts a character to its numeric code, and chr() converts a number back to a character.
- In ASCII, lowercase 'a' is 97; adding a shift directly to character codes can produce punctuation when a letter passes the end of the alphabet.
- ASCII began as a 7-bit character set with 128 values, and its first 128 code points are included in Unicode.
- Subtracting 97 maps lowercase ASCII letters into a zero-based range where 'a' is 0 and 'z' is 25.
- The encryption calculation adds the key and applies modulo 26, wrapping values such as 38 back to 12.
- Adding 97 after the modulo operation maps the result back into lowercase ASCII; the resulting character is appended to ciphertext.
- The Python decryption loop tries each key in range(26), subtracts that key from every ciphertext letter, and uses modulo 26 to wrap around.
- Printing each candidate plaintext makes the correct result recognizable without knowing the key in advance.
- The example reveals “Minnesota United Football Club” at shift 17, demonstrating why a Caesar cipher is not secure.
- The Vigenère cipher replaces a single numeric shift with a keyword repeated across the plaintext, such as repeating KEY over “HELLO WORLD.”
- Each plaintext letter is combined with its corresponding keyword letter using values modulo 26; decryption reverses the operation.
- The lecture places Vigenère-style methods in historical use, including the American Civil War and World War I, while noting that repeated patterns can help cryptanalysis.
- A substitution key pairs each alphabet letter with a replacement letter, agreed upon in advance by the communicating parties.
- Python's alphabet.index(letter) finds a plaintext letter's position, and the program selects the key character at the same position.
- This approach avoids the arithmetic used in Caesar encryption and can also obscure spaces when the key maps a space to a letter.
- To decrypt, the program finds each ciphertext character's index in the key and uses that index to retrieve the corresponding character from the alphabet.
- The decoded passage begins, “The sun was shining on the sea,” illustrating the reverse lookup process.
- The encryption and decryption programs share the same paired alphabet and key but search opposite sides of the mapping.
- The lecture identifies RSA—named for Rivest, Shamir, and Adleman—as a public-key cryptography system published in 1977.
- RSA's security is connected to the difficulty of factoring products of large prime numbers.
- The lecture emphasizes that cryptographic systems need expert mathematical scrutiny and that some keys have been broken, even though RSA remains widely useful.
- A one-time pad uses matching copies of a randomized key shared by the sender and recipient to transform a message.
- The lecture describes it as the strongest form of secure communication because ciphertext outputs are not distinguished by an exploitable mathematical pattern.
- Generating truly random keys is difficult: computers typically produce pseudorandom values, while physical methods such as drawing numbered balls can supply randomness.
- A man-in-the-middle attack convinces one or both parties that the attacker is the intended recipient.
- An attacker can relay encrypted messages, collect enough material to attempt decryption, or alter messages after reading them.
- The lecture stresses that attackers may exploit communication and identity checks rather than break the cipher directly.
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Professor Rosen.