Lecture 12 (Sherriff) - Encryption

Lecture Date: Monday, February 9

We’re going to take a small side trip away from the individual components of a program and look at a good use for what we’ve written so far.

Cryptography Definitions

What is purpose of encryption? Why use it? Do you use encryption? Examples: cell phone, gaming, banking, Internet

Definitions:

  • Cryptography - secret or hidden writing
  • Encryption/Decryption - the act of turning normal text (“plaintext”) into garbled mess (“ciphertext”)
  • Cipher - the algorithm (step-by-step process) for conversion

History of Cryptography

  • Early years (before modern era)
  • Concerned solely with keeping messages secret
  • Between governments, military leaders, spies, etc
  • Early cryptography - none… because not many people could read
  • First ciphers went into three main categories: physical, transposition and substitution

Physical ciphers - ciphers created using objects

Scytale: This type of cipher uses a ribbon or other long piece of material wrapped around a particular width cylinder to encrypt a message.
sytale
Cryptex: The thing from DaVinci Code that Prof. Langdon has to open… the keyword was “APPLE”…
cryptex

Transposition ciphers - kinda like word scrambles, but with a specific, regular way for scrambling

Route: In a route cipher, the plaintext is first written out in a grid of given dimensions, then read off in a pattern given in the key.

W R I O R F E O E
E E S V E L A N J
A D C E D E T C X

The key might specify “spiral inwards, clockwise, starting from the top right”. That would give a cipher text of: EJXCTEDECDAEWRIORFEONALEVSE

Substitution ciphers - replacing a letter with another letter

Pigpen (Masonic): Sometimes it’s easiest just to replace each letter with a symbol to fool whoever is trying to read your message! The Pigpen (or Masonic) cipher uses these symbols to do just that.
pigpen

Caesar: A Caesar cipher is a simple shift cipher in which we move every character over by a certain number of letters. Basically like a decoder ring. Traditionally, Caesar ciphers move all characters over by 3. So, when you encrypt, the letter “A” becomes the letter “D”. When you decrypt, the letter “P” becomes the letter “M,” and so on.

Vigenere: Caesar can be pretty easy to decrypt - you only have to test …. how many different keys? So, what if we shifted each letter by a different letter. In other words, instead of shifting each letter by the same number (like 3), we shift each letter by a regular pattern, using another word.

If we encrypt:

WE ARE DISCOVERED FLEE AT ONCE

with the keyword LEAD, we get:

W + L = ?
Convert to numbers: 22 + 11 = 33
Wrap around: 33 - 26 = 7
Convert back to a letter: 7 = H

So the first letter is H. But this will take a long time to do this way! Thankfully, we have a chart we can use!

Vignere Cipher Chart

How might we code this? How could we use loops?

Let’s look at an example: ShuffleCipher.java

What about more modern forms of encryption? What is the concept of a public key and a private key? How does Netbadge work? What about HTTPS?