Cryptography - Brown University

18
CS8: A First Byte of Computer Science Prof. Michael Littman Cryptography

Transcript of Cryptography - Brown University

CS8: A First Byte of Computer ScienceProf. Michael Littman

Cryptography

Kinds of CodesCodes: ๏ Compression: use fewer bits to transmit a message ๏ Error correction: make it fixable if slightly changed ๏ Cryptography: make it readable only with a key

- Authentication - Time stamping - Secret messages - Secure transactions - Privacy

Letter Substitutions๏ One way to encode a message to make it hard to read for

people without the secret is to switch letters for other letters. This cypher moves each letter forward one position in the alphabet.

!๏ So, “ADDER” becomes? ๏ Decoding is very similar; it makes substitutions to reverse

the effect.

!๏ So “TUFFET” is actually?

A B C D E F G H I J K L M N O P Q R S T U V W X Y ZB C D E F G H I J K L M N O P Q R S T U V W X Y Z A

A B C D E F G H I J K L M N O P Q R S T U V W X Y ZZ A B C D E F G H I J K L M N O P Q R S T U V W X Y

Letter Substitutions๏ What interesting property does this encoding

scheme have? !

!

๏ RU BLF PMLD SLD GL VMXLWV Z NVHHZTV, BLF XZM WVXLWV RG.

A B C D E F G H I J K L M N O P Q R S T U V W X Y ZZ Y X W V U T S R Q P O N M L K J I H G F E D C B A

PYVPXRE DHVMV NZ VZCERFFRQ GUNG LBH PNA ERNQ EBG GUVEGRRA. ABG RIRELBAR PNA QRPBQR ZRFFNTRF YVXR GUNG. JUNG QB LBH FNL GB GUNG? N. GUNAX LBH IREL ZHPU. O. JUNG QB LBH ZRNA? V WHFG CVPXRQ GUVF BAR NG ENAQBZ. P. GB OR UBARFG, V PBHYQA'G NPGHNYYL ERNQ VG. V WHFG GBBX GUR YBATRFG BAR. Q. V JVFU V UNQ ZBER GVZR. V BAYL TBG NF SNE NF "V". R. BBCF.

ROT 13

๏ This code has a similar property. ๏ Each letter is rotated forward 13 spaces in the

alphabet. ๏ It is commonly used on the Internet to prevent

spoilers, because most people can’t read it directly. ๏ Do you want another shot at it?

A B C D E F G H I J K L M N O P Q R S T U V W X Y ZN O P Q R S T U V W X Y Z A B C D E F G H I J K L M

PYVPXRE DHVMV NZ VZCERFFRQ GUNG LBH PNA ERNQ EBG GUVEGRRA. ABG RIRELBAR PNA QRPBQR ZRFFNTRF YVXR GUNG. JUNG QB LBH FNL GB GUNG? N. GUNAX LBH IREL ZHPU. O. JUNG QB LBH ZRNA? V WHFG CVPXRQ GUVF BAR NG ENAQBZ. P. GB OR UBARFG, V PBHYQA'G NPGHNYYL ERNQ VG. V WHFG GBBX GUR YBATRFG BAR. Q. V JVFU V UNQ ZBER GVZR. V BAYL TBG NF SNE NF "V". R. BBCF.

I AM IMPRESSED THAT YOU CAN READ ROT THIRTEEN. NOT EVERYONE CAN DECODE MESSAGES LIKE THAT. WHAT DO YOU SAY TO THAT? A. THANK YOU VERY MUCH. B. WHAT DO YOU MEAN? I JUST PICKED THIS ONE AT RANDOM. C. TO BE HONEST, I COULDN'T ACTUALLY READ IT. I JUST TOOK THE LONGEST ONE. D. I WISH I HAD MORE TIME. I ONLY GOT AS FAR AS "I". E. OOPS.

Harder Codes๏ ROT-13 isn’t a very secure code because its decoding

method is so well known. ๏ Can also do more general mappings. !!

๏ Harder to reverse. - Know the reversing code. - Solve the cryptogram. - Sort the table by the second row.

A B C D E F G H I J K L M N O P Q R S T U V W X Y ZQ A J O I T R X V S F L Y D G M C Z U W N H E P B K

B Y Q N W K O V E C Z L P U D X A G J F S I T H M RA B C D E F G H I J K L M N O P Q R S T U V W X Y Z

code(HELLO) = XILLG

code-1(XILLIG) = HELLOcode-1(HELLO) = VWLLD

Public Key Idea๏ Let’s say there are a bunch of codes out there.

- 1025 different encoding/decoding schemes! ๏ Each of us adopts an encoding scheme and announces it

to the world. ๏ We also have a decoding scheme, which we keep private.

- Sam(x): Sam’s encoding of message x. (Anyone.) - Sam-1(x): Sam’s decoding of message x. (Sam only.) - Alexa(x): Alexa’s encoding of message x. (Anyone.) - Alexa-1(x): Alexa’s decoding of message x. (Alexa only.)

Code Algebra๏ What is Sam(x)? ๏ Who can compute it? ๏ What is Alexa-1(Alexa(x))? ๏ Who can compute it? ๏ General: Name-1(Name(x)) = Name(Name-1(x)) = x.

๏ But: If you know Name, you can’t figure out Name-1.

Code Quiz

What is code(code-1(code(WINESAP)))? A. EVDIUQM B. TEUWJBX C. VXGHDJB D. IHOVNCY E. WINESAP

A B C D E F G H I J K L M N O P Q R S T U V W X Y ZQ A J O I T R X V S F L Y D G M C Z U W N H E P B K

Send A Secret๏ Alexa has a message x for Sam. ๏ She computes and sends y=Sam(x). ๏ Message y looks like gibberish to everyone. ๏ Sam computes Sam-1(y)=Sam-1(Sam(x))=x and

recovers the original message.

Authenticate๏ Sam wants to be sure Alexa is really Alexa. ๏ Sam sends a message x to Alexa. ๏ She computes and sends y=Alexa-1(x). ๏ Message y can only be created by Alexa. ๏ Sam computes Alexa(y)=Alexa(Alexa-1(x))=x and is

reassured that only the true Alexa can make a y with this property.

Other Operations๏ Secret message that only Alexa and Sam can

decode by working together (and). ๏ Secret message that either Alexa or Sam can

decode alone (or). ๏ Digital signature.

Making It Work๏ Need something that supports:

- private code - public code - they are inverses of each other - knowing the public code doesn’t tell you the

private code without a lot of work

A Little Number Theory๏ Let’s say that I have a secret number x and you

have one y. Can we agree on a secret number without giving it away to anyone who overhears us?

๏ First, note: z = (ax)y = (ay)x (right?) ๏ If you know z and y (and a), can you get x? ๏ Yes, via log:

- log(z) = x log(ay), x = log(z)/log(ay) - inverse operation.

A Little More Number Theory๏ In clock arithmetic, the equality still holds: ๏ First, note: z = (ax)y = (ay)x (mod b) ๏ If you know z and y (and a), can you get x? ๏ No! “Discrete log” not solvable in general.