Enigma

Jed Rembold

November 12, 2024

Announcements

  • Graphics Contest entry due tonight if you want to submit something!
  • Exams results most likely back by Friday, but I am trying for Wednesday
  • This week: the Enigma project! Which we are introducing today
  • Polling: polling.jedrembold.prof

Review Question

What is the printed value of the below code?

A = [
    {'name': 'Jill',  'weight':125, 'height':62},
    {'name': 'Sam',   'height':68},
    {'name': 'Bobby', 'height':72},
]
A.append({'weight':204, 'height':70, 'name':'Jim'})
B = A[1]
B['weight'] = 167
A.append(B)
print([d['weight'] for d in A if 'weight' in d])
  1. [125,70,167]
  2. [125,167,204,167]
  1. [125,204,167]
  2. This would error

Registration Thoughts

Registration Times

  • Registration is coming up!
Year Registration Date Registration Day
4 11/18 Monday
3 11/19 Tuesday
2 11/21 Thursday
1 11/25 Following Monday

Advising

  • Everyone needs an in-major advisor
  • Interested in declaring a major in Computer Science or Data Science?!
    • Email registrar@willamette.edu
    • CC myself or whomever you’d like to be your advisor
    • Include your ID #
    • Say which majors you want to declare
      • You can add/drop majors/advisors anytime

Continuing in CS

  • If you are interested in continuing with a CS major, in order of urgency, you should be considering:
    • CS 152: Data Structures
      • Prereq for most other higher CS courses
    • MATH 251W: Foundations of Advanced Math
      • Will likely fill
      • Has an on-paper-only calculus requirement. Contact the instructor to join.
    • DATA 352W: Data Ethics

Continuing in DATA

  • If you are interested in continuing in or majoring in DATA:
    • DATA 151
    • DATA 152
    • DATA 352W: Data Ethics
    • MATH 280
      • Talk to instructor to join if missing calculus

Other Computational Courses

  • There are other computational/data courses being offered that you likely meet the pre-reqs for:
    • DATA 275: Data in the Cosmos
    • CS 370: Python for Data Science
    • PHEAL 214: Epidemiology
    • ENVS 250: GIS
    • DATA 429: Survey Design and Sampling (Needs stats and this will likely fill fast)

Say it Secret

Cryptography

  • The science of encoding messages to keep their contents secret–and the symmetric problem of decoding those messages–is called cryptography.
  • First recorded cryptographic algorithm attributed to Julius Caesar. The Roman historian Suitonius writes that:

If [Caesar] had anything confidential to say, he wrote it in cipher, that is, by so changing the order of the letters of the alphabet, that not a word could be made out.

  • In a Caesar Cipher, each letter is advanced a fixed distance in the alphabet, wrapping around to the start if necessary
    • A +3 Caesar cipher would make the following mappings

Letter Substitution Ciphers

  • A letter-substitution cipher (informally called a cryptogram) is a code in which each letter in the original text is replaced with some other letter.
    • The substitution pattern remains the same throughout the message
    • Any letter can be mapped to any other unused letter, no order is necessary
  • One of the more famous cryptograms was written by Edgar Allen Poe in his short story “The Gold Bug”
    • Described in his story how the message could be decoded by mapping the most common letters in the message to the most commonly used letters in the English language

World War II

Alan Turing

  • One of the most important contributors to computer science is Alan Turing, who made critical contributions in the theory of computation, hardware design, and artificial intelligence
  • During WW2, Turing headed the mathematics division at Bletchley Park in England, which broke the German Enigma code
  • Tragically, Turing committed suicide in 1954 after being convicted on a charge of “gross indecency” as a homosexual
    • Prime Minister Gordon Brown issued a public apology in 2009
Alan Turing (1912-1954)

The Enigma Machine

Actual Enigma Machine
Enigma Diagram

Enigma Rotors

StepInButton ResetButton

The Enigma Internals

ABCDEFGHIJKLMNOPQRSTUVWXYZJLYmedium rotorfast rotorslow rotorreflector
 

Operation of the Enigma Machine

  • Whenever a letter is typed, the following happens:
    1. The force of the key press advances the fast rotor one position. If the rotor wraps from Z to A, this advances the next rotor by one increment as well.
    2. An electric signal is fed into the wire corresponding to the key, which then flows through seven letter-substitution steps
      • Through the fast rotor from right to left
      • Through the medium rotor from right to left
      • Through the slow rotor from right to left
      • Through the reflector, which turns the signal around
      • Through the slow rotor from left to right
      • Through the medium rotor from left to right
      • Through the fast rotor from left to right and on to the lamp

Encoding “A”

ABCDEFGHIJKLMNOPQRSTUVWXYZJLZmedium rotorfast rotorslow rotorreflector
 

Encoding “A” Again

ABCDEFGHIJKLMNOPQRSTUVWXYZJMAmedium rotorfast rotorslow rotorreflector
 

Project 4 Milestones

  • Project 4 has slightly more milestones than past projects, but each is still meant to give you a testable aspect of the program that you can bite off one piece at a time
    • Milestone 0: Activate the keyboard when pressed
    • Milestone 1: Connect the keys directly to the lamps (no encryption)
    • Milestone 2: Design and implement rotors
    • Milestone 3: Implement one stage in the encryption (through 1 rotor)
    • Milestone 4: Implement the full encryption path
    • Milestone 5: Make the rotors advance properly each key press
  • Web examples exist for helping you test each step of the process, linked here and in the guide.

Model-Controller-View

  • The Enigma project is designed using the common model, controller, view paradigm
  • Breaks an interactive program up into 3 pieces:
    • The controller: the piece that deals with user input
    • The view: the piece that handles graphical output
    • The model: the piece that controls what should be happening at any given time

Modeling

  • In the Enigma project, the view and the controller are handled for you
    • Both are actually handled in the same module
    • Both export various methods that you can use to get input or interact with them from within the model
  • You are responsible for writing the code that comprises the model
  • There is also a constants module, where all of the various constants that you may need are stored

Let’s Talk About Sets

Pythonic Sets

  • Enclosed within squiggly brackets

  • No key-value pairs, just single values separated by commas

    digits = { 0, 1, 2, 3, 4, 6, 7, 8, 9 }
    squares = { 0, 1, 4, 9 }
    primary = { "red", "green", "blue" }
  • Set elements must be immutable

  • Sets themselves are generally mutable

  • Can not create an empty set just using { }!

    • Python assumes this to be an empty dictionary!
    • Must instead use set().

Set Operations

  • The fundamental set operation is membership (∈)
    • 3 ∈ primes
    • 3 ∉ evens
    • red ∈ primary
    • -1 ∉ N
  • The union of the sets \(A\) and \(B\) (\(A \cup B\)) consists of all elements in either \(A\) or \(B\) or both.
  • The intersection of the sets \(A\) and \(B\) (\(A \cap B\)) consists of all elements in both \(A\) and \(B\).
  • The set difference of \(A\) and \(B\) (\(A - B\)) consists of all elements in \(A\) but not in \(B\).
  • The symmetric set difference of \(A\) and \(B\) (\(A\triangle B\)) consists of all elements in \(A\) or \(B\) but not in both.

Python Implementations

  • Python’s built-in implementation of sets supports all these same operations
  • Can either use appropriately named methods on sets or operators between sets
  • Membership 3 in primes
  • Union: A.union(B) A | B
  • Intersection A.intersection(B) A & B
  • Difference A.difference(B) A - B
  • Symmetric difference A.symmetric_difference(B) A ^ B

Venn Diagrams

  • A Venn Diagram is a graphical representation of a set which indicates common elements as overlapping areas
  • The following Venn diagrams illustrate the effect of the 4 primary set operations

image/svg+xml A B A ∪ B
image/svg+xml A B A ∪ B A B A ∩ B B A - B A

image/svg+xml A B A ∪ B A B A ∩ B
image/svg+xml A B A ∪ B A B A ∩ B A B A - B A B A ∆ B

Practice

If we have the following sets from earlier:

digits = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
evens = { 0, 2, 4, 6, 8 }
odds = { 1, 3, 5, 7, 9 }
primes = { 2, 3, 5, 7 }
squares = { 0, 1, 4, 9 }

What is the value of each of the following:

  • evens ∪ squares
  • odds ∩ primes
  • primes - evens
  • odds ∆ squares
// reveal.js plugins