Cryptography

Reading: Chapter 11

wherein the Alice-Bob subplot is unveiled

STARRING
AliceBobEveSpot

Prologue: Alice and Bob want to talk. Clever, evil Eve wants to eavesdrop. Alice and Bob wonder what to do.

Private-key cryptography

Alice and Bob agree on a key in private. Now they can talk alound, encoding messages with the key.

Drats!

Fine, but what's a key and how can we use it?

Kaptain Krunch Secret Decoder Ring

Arr!

Try a shuffling of letters. Alice and Bob agree on the mapping as their key.

original     _ A B C D E F G H I J K L M N O ...
destination  @ A X J E W U I D C H T N M B R ...

Alice maps her message using the mapping.

   I _ D O
-> C @ E R
She sends, ``C@ER.'' To decrypt, Bob reverses the mapping
   C @ E R
<- I _ D O

But Eve's clever!

Any long English messages can be decoded by analyzing letter frequency.

The letter occurring most is probably an `E'.

Newspaper cryptograms show how easy breaking Kaptain Krunch's code is.

Shiver me timbers!

What do we want?

We can think of our belief about the messages contents as a probability distribution.

The encrypted message should not alter our suspicions; i.e., for every message x,

  Pr[x is original, given encryption] = Pr[x is original].

How can we do it?

Say Alice and Bob agree to a series of random numbers between 0 and 26.

   2, 23, 20, 8, 16, ...

To encrypt, Alice adds numbers to corresponding letters.

   I    _    D    O
 + 2  +23  +20  + 8
 ---  ---  ---  ---
   K    W    X    W
Bob subtracts to get original.
   K    W    X    W
 - 2  -23  -20  - 8
 ---  ---  ---  ---
   I    _    D    O

This is called the one-time pad.

Bayes' Theorem

Fact:

  Pr[x and y] = Pr[x given y] Pr[y]
  Pr[x and y] = Pr[y given x] Pr[x]
This implies Bayes' Theorem:
                  Pr[x] Pr[y given x]
  Pr[x given y] = -------------------
                         Pr[y]

Arf?

Does it work?

Pr[X is original, given encryption M]
 
    Pr[X is original] Pr[M is encryption, given X]
  = ----------------------------------------------
                   Pr[M is encryption]

But...

                                       k
  Pr[M is encryption, given X] = (1/27)
Independence!

And...

  Pr[M is encryption] =  sum    Pr[K is key] Pr[M is X + K]
                        keys K

                                      k
                      =  sum    (1/27)    Pr[X is M - K]
                        keys K

                               k
                      =  (1/27)    sum    Pr[X is M - K]
                                  keys K

                               k
                      =  (1/27)

So:

  Pr[X is original, given encryption M] = Pr[X is original]
Darn!

Public-key cryptography

Often Alice and Bob can't communicate key in private. This is a job for public-key cryptography.

Now Bob has two keys, one published, one kept to himself.

A message encrypted with the public key can only be decrypted with a private key.

RSA Cryptosystem

The most popular public-key cryptosystem is RSA. (PGP is one implementation.)

In RSA, the public key is a product of two large prime numbers. The private key has the two primes.

RSA is not as secure as one-time pad. It is broken if the public key is factored.

But after 2,500 years of looking, we still don't know a fast factoring algorithm.

Cryptography Applications

Communicating an Average

Alice, Bob, Krunch, and Spot just got their test grades.

95888250

They want to know their average score, but nobody wants to reveal their grades. What can they do?

Modulo Arithmetic

x mod N is the remainder when x is divided by N.

For addition, this gives wrap-around behavior. Notice that modulo addition is commutative and associative.

We take N to be 401.

The Algorithm

All behave the same.

  1. Bob chooses rBA, rBS, rBK randomly between 0 and 400. He calculates rBB so that
      (rBA + rBS + rBK + rBB) mod 401 = Bob's score (88)
    
  2. He sends rBA to Alice, receives rAB. He sends rBS, receives rSB. He sends rBK, receives rKB.
  3. Compute
      cB = (rAB + rSB + rKB + rBB) mod 401
    
    Give cB to everybody, get cA, cS, and cK.
  4. The sum of all scores is (cB + cA + cS + cK) mod 401.

Why does it work?

 
              sends to whom
who     Alice  Bob   Spot  Krunch score
Alice   135    240   301   221      95
Bob     285    363   109   133      88
Spot    135    300   334    83      50
Krunch  132      5   230   116      82
total   286    106   172   152     315

Ankur's public-key cryptosystem attack

In class, Ankur suggested that in a public-key cryptosystem Eve might be able to guess the message Alice sends, encrypt it with Bob's key, and thus verify what it was Alice sent. I didn't have an answer to it then.

There is an answer, though: Alice can include in the message two parts.

  1. A one-time pad key, K
  2. The original message encrypted by K.
Now Alice encrypts both parts together using Bob's public key, and then she can send it to Bob.