Lecture 13: Astrophysics and Cryptology David Evans CS200: Computer Science

advertisement

Lecture 13:

Astrophysics and Cryptology

CS200: Computer Science

University of Virginia

Computer Science

David Evans http://www.cs.virginia.edu/~evans

Menu

• Quicksort Recap

• DeGrasse Tyson’s Essay

• Cryptography

(CS588 condensed)

13 February 2002 CS 200 Spring 2002 2

Quicksort

C. A. R. Hoare, 1961

13 February 2002 CS 200 Spring 2002 3

Quicksort

(define (quicksort cf lst)

(if (null? lst) lst

(append

(quicksort cf

(filter (lambda (el) (cf el (car lst)))

(cdr lst)))

(list (car lst))

(quicksort cf

(filter (lambda (el) (not (cf el (car lst))))

(cdr lst))))))

13 February 2002 CS 200 Spring 2002 4

filter

(define (filter f lst)

(insertlg

(lambda (el rest)

(if (f el) (cons el rest) rest)) lst null))

How much work is filter?

(

n

)

13 February 2002 CS 200 Spring 2002 5

Quicksort

(define (quicksort cf lst)

(if (null? lst) lst

(append

(quicksort cf

(filter (lambda (el) (cf el (car lst)))

(cdr lst)))

(list (car lst))

(quicksort cf

(filter (lambda (el) (not (cf el (car lst))))

(cdr lst))))))

• filter is

( n )

• How much work is Quicksort if the input list is sorted?

Worst Case:

( n 2 ) we filter n times, each is

( n )

13 February 2002 CS 200 Spring 2002 6

Quicksort

(define (quicksort cf lst)

(if (null? lst) lst

(append (quicksort cf

(filter (lambda (el) (cf el (car lst))) (cdr lst)))

(list (car lst))

(quicksort cf

(filter (lambda (el) (not (cf el (car lst)))) (cdr lst))))))

• filter is

( n )

• How much work is Quicksort if the input list is random?

Each time we split the list, each piece is approximately ½ the length of the original list

We need log

Best (Average) Case:

( n log we filter

2 n splits to get down to empty list log

2

2 n ) n times, each is

( n )

13 February 2002 CS 200 Spring 2002 7

> (define r1000 (rand-int-list 1000))

> (time (sort < r1000)) cpu time: 1372 real time: 1372 gc time: 0

> (time (quicksort < r1000)) cpu time: 71 real time: 70 gc time: 0

> (define r2000 (rand-int-list 2000))

> (time (sort < r2000)) cpu time: 5909 real time: 5909 gc time: 0

> (time (quicksort < r2000)) cpu time: 180 real time: 180 gc time: 0

> (time (quicksort < (revintsto 1000))) cpu time: 2684 real time: 2684 gc time: 0

13 February 2002 CS 200 Spring 2002 8

12000

10000

8000

6000

4000

2000

0

13 February 2002

Growth of time to sort random list

CS 200 Spring 2002 n 2

(bubblesort) n log

2 n

(quicksort)

9

Science’s Endless Golden Age

13 February 2002 CS 200 Spring 2002 10

Astrophysics

• “If you’re going to use your computer to simulate some phenomenon in the universe, then it only becomes interesting if you change the scale of that phenomenon by at least a factor of 10. … For a 3D simulation, an increase by a factor of 10 in each of the three dimensions increases your volume by a factor of 1000.”

• How much work is astrophysics simulation (in  notation)?

( n 3 )

When we double the size of the simulation, the work octuples!

(Just like oceanography octopi simulations)

13 February 2002 CS 200 Spring 2002 11

Astrophysics and Moore’s Law

• Simulating universe is

(

n 3

)

• Moore’s law: computing power doubles every 18 months

• Tyson: to understand something new about the universe, need to scale by 10x

• How long does it take to know twice as much about the universe?

13 February 2002 CS 200 Spring 2002 12

(define (computing-power nyears)

(if (= nyears 0) 1 (* 1.587 (computing-power (- nyears 1)))))

;;; doubling every 18 months = ~1.587 * every 12 months

(define (simulation-work scale) (* scale scale scale))

;;; Simulation is O(n^3) work

(define (log10 x) (/ (log x) (log 10)))

;;; primitive log is natural (base e)

(define (knowledge-of-universe scale) (log10 scale))

;;; knowledge of the universe is log 10 the scale of universe we can simulate

(define (find-knowledge-of-universe nyears)

(define (find-biggest-scale scale)

; today, can simulate size 10 universe

(if (> (/ (simulation-work scale) 1000)

(computing-power nyears))

(- scale 1)

(find-biggest-scale (+ scale 1))))

CS 200 Spring 2002 13

> (find-knowledge-of-universe 0)

1.0

> (find-knowledge-of-universe 1)

1.041392685158225

> (find-knowledge-of-universe 2)

1.1139433523068367

> (find-knowledge-of-universe 5)

1.322219294733919

> (find-knowledge-of-universe 10)

1.6627578316815739

> (find-knowledge-of-universe 15)

2.0

> (find-knowledge-of-universe 30)

3.00560944536028

> (find-knowledge-of-universe 60)

5.0115366121349325

> (find-knowledge-of-universe 80)

6.348717927935257

13 February 2002

Will there be any mystery left in the Universe when you die?

CS 200 Spring 2002 14

Correction from Lecture 1:

Liberal Arts

• Grammar: study of meaning in written expression

Yes, we need to understand meaning to describe computations

• Rhetoric: comprehension of verbal and written discourse

• Logic: argumentative discourse for components, discourse between programs and users

Logic for controlling discovering truth and reasoning about computations

• Arithmetic: understanding numbers

Yes (last few lectures)

• Geometry: quantification of space

Yes (PS 1, 2, 3)

• Music: number in time

Yes, its called GE B

• Astronomy: laws of the planets and for a reason!

stars

Interfaces between

13 February 2002 CS 200 Spring 2002 15

Correction from Lecture 1:

Bold (Possibly Untrue) Claim

This course is the most consistent with the original intent of a Liberal Arts education of any course offered at UVA this semester!

since Mr. Jefferson founded it!

13 February 2002 CS 200 Spring 2002 16

The Endless Golden Age

• Golden Age – period in which knowledge/quality of something doubles quickly

• At any point in history, half of what is known about astrophysics was discovered in the previous 15 years!

• Moore’s law today, but other advances previously: telescopes, photocopiers, clocks, etc.

13 February 2002 CS 200 Spring 2002 17

The Real Golden Rule?

Why do fields like astrophysics, medicine, biology and computer science (?) have “endless golden ages”, but fields like

– music (1775-1825)

– rock n’ roll (1962-1973, or whatever was popular when you were 16)

– philosophy (400BC-350BC?)

– art (1875-1925?)

– soccer (1950-1974)

– baseball (1925-1950)

– movies (1930-1940) have short golden ages?

What about mathematics?

13 February 2002 CS 200 Spring 2002 18

Cryptology

( CS588 Condensed)

13 February 2002 CS 200 Spring 2002 19

Terminology

Plaintext Encrypt

Insecure Channel

Ciphertext

Decrypt Plaintext

Alice

13 February 2002

Eve

C = E(P)

P = D(C)

E must be invertible: P = D (E (P))

CS 200 Spring 2002

Bob

20

Plaintext

“The enemy knows the system being used.”

Claude Shannon

Encrypt

Insecure Channel

Ciphertext

Decrypt Plaintext

Alice

13 February 2002

K

Eve

C = E(P, K)

P = D(C, K)

CS 200 Spring 2002

K

Bob

21

13 February 2002

Jefferson Wheel Cipher

CS 200 Spring 2002 22

13 February 2002

Enigma

• About 50,000 used by Nazi’s in

WWII

• Modified throughout WWII, believed to be perfectly secure

• Broken by Bletchley Park led by Alan Turing (and 30,000 others)

• First computer (Collossus) developed to break Nazi codes

(but kept secret through 1970s)

• Allies used decrypted Enigma messages to plan D-Day

CS 200 Spring 2002 23

Enigma

Coming to US in April!

13 February 2002 CS 200 Spring 2002 24

Bletchley Park

13 February 2002 CS 200 Spring 2002 25

Lorenz Cipher Machine

13 February 2002 CS 200 Spring 2002 26

Perfectly Secure Cipher:

One-Time Pad

• Mauborgne/Vernam [1917]

• xor ( 

):

0

0 = 0 1

0 = 1

0

1 = 1 1

1 = 0 a

 a = 0 a

0 = a a

 b

 b = a

• E(P, K) = P 

K

D(C, K) = C

K = (P

K)

K = P

13 February 2002 CS 200 Spring 2002 27

Why perfectly secure?

For any given ciphertext, all plaintexts are equally possible.

Ciphertext: 0100111110101

Key: 1100000100110

Plaintext:

13 February 2002 CS 200 Spring 2002 28

If its “perfect” why is it broken?

• Cannot reuse K

• Need to generate truly random bit sequence as long as all messages

• Need to securely distribute key

13 February 2002 CS 200 Spring 2002 29

“One-Time” Pad’s in Practice

• Lorenz Machine –

Nazi high command in WWII

– Pad generated by 12 rotors

– Receiver and sender set up rotors in same positions

– One operator retransmitted a message (but abbreviated message header the second time!)

– Enough for Bletchley Park to figure out key – and structure of machine that generated it!

– But still had to try all configurations

13 February 2002 CS 200 Spring 2002 30

Colossus – First

Programmable

Computer

• Bletchley Park, 1944

• Read ciphertext and

Lorenz wheel patterns from tapes

• Tried each alignment, calculated correlation with

German

• Decoded messages (63M letters by 10 Colossus machines) that enabled Allies to know German troop locations to plan D-Day

• Destroyed in 1960, kept secret until 1970s

13 February 2002 CS 200 Spring 2002 31

13 February 2002

From http://www.codesandciphers.org.uk/lorenz/fish.htm

CS 200 Spring 2002 32

Problem Set 4

• Break a simplified Lorenz Cipher

• Removed one wheel, made initial positions of all groups of wheels have to match

• Small rotors

• Its REALLY AMAZING that the British were able to break the real Lorenz in 1943 and it is still hard for us today!

13 February 2002 CS 200 Spring 2002 33

Motivation Helps…

Confronted with the prospect of defeat, the Allied cryptanalysts had worked night and day to penetrate German ciphers. It would appear that fear was the main driving force, and that adversity is one of the foundations of successful codebreaking.

Simon Singh, The Code Book

13 February 2002 CS 200 Spring 2002 34

Modern Ciphers

• 128-bit keys, encrypt 128-bit blocks

• Brute force attack

– Try 1 Trillion keys per second

– Would take 10790283070806000000 years to try all keys!

– If that’s not enough, can use 256-bit key

• No known techniques that do better than brute force search

13 February 2002 CS 200 Spring 2002 35

Charge

• PS4

– No new Computer Science concepts

– You should be able to do it now

– Lots of practice with lists and recursion

– No bombs dropping, but a little bit of motivation

(prize for first person/group to decipher secret message)

13 February 2002 CS 200 Spring 2002 36

Download