shift cipher - umd

29
Shift Cipher For 0 ≤ ≤ 25, the th plaintext character is shifted by some value 0 ≤ ≤ 25 ( 26). E.g. k = 3 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 z D E F G H I J K L M N O P Q R S T U V W X Y Z A B C goodmorning JRRGPRUQLQJ

Upload: others

Post on 03-Nov-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Shift Cipher - UMD

Shift Cipher

• For 0 ≤ 𝑖 ≤ 25, the 𝑖th plaintext character is shifted by some value 0 ≤ 𝑘 ≤ 25 (𝑚𝑜𝑑 26).

– E.g. k = 3

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 z

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

goodmorning JRRGPRUQLQJ

Page 2: Shift Cipher - UMD

Frequency Analysis If plaintext is known to be grammatically correct English, can use frequency analysis to break monoalphabetic substitution ciphers:

Page 3: Shift Cipher - UMD

An Improved Attack on Shift/Caesar Cipher using Frequency Analysis

• Associate letters of English alphabet with numbers 0. . .25

• Let 𝑝𝑖 denote the probability of the 𝑖-th letter in English text.

• Using the frequency table:

𝑝𝑖225

𝑖=0 ≈ 0.065

• Let 𝑞𝑖 denote the probability of the 𝑖-th letter in this ciphertext: # of occurrences/length of ciphertext

• Compute 𝐼𝑗 = 𝑝𝑖 ⋅ 𝑞𝑖+𝑗25𝑖=0 for each possible shift value

𝑗

• Output the value 𝑘 for which 𝐼𝑘 is closest to 0.065.

Page 4: Shift Cipher - UMD

Vigenere Cipher (1500 A.D.)

• Poly-alphabetic shift cipher: Maps the same plaintext character to different ciphertext characters.

• Vigenere Cipher applies multiple shift ciphers in sequence.

• Example:

Plaintext: t e l l h i m a b o u t m e

Key: c a f e c a f e c a f e c a

Ciphertext: W F R Q K J S F E P A Y P F

Page 5: Shift Cipher - UMD

Breaking the Vigenere cipher

• Assume length of key t is known.

• Ciphertext 𝐶 = 𝑐1, 𝑐2, 𝑐3, …

• Consider sequences

– 𝑐1, 𝑐1+𝑡 , 𝑐1+2𝑡 , …

– 𝑐2, 𝑐2+𝑡 , 𝑐2+2𝑡 , …

– . .

• For each one, run the analysis from before to determine the shift 𝑘𝑗 for each sequence 𝑗.

Page 6: Shift Cipher - UMD

Index of Coincidence Method • How to determine the key length? • Consider the sequence: 𝑐1, 𝑐1+𝑡 𝑐1+2𝑡, … where 𝑡

is the true key length

• We expect 𝑞𝑖225

𝑖=0 ≈ 𝑝𝑖225

𝑖=0 ≈ 0.065 • To determine the key length, try different values

of 𝜏 and compute 𝑆𝜏 = 𝑞𝑖225

𝑖=0 for subsequence 𝑐1, 𝑐1+𝜏, 𝑐1+2𝜏, …

• When 𝜏 = 𝑡, we expect 𝑆𝜏 to be ≈ 0.065 • When 𝜏 ≠ 𝑡, we expect that all characters will

occur with roughly the same probability so we expect 𝑆𝜏 to be ≈

1

26≈ 0.038.

Page 7: Shift Cipher - UMD

What have we learned?

• Sufficient key space principle:

– A secure encryption scheme must have a key space that cannot be searched exhaustively in a reasonable amount of time.

• Designing secure ciphers is a hard task!!

– All historical ciphers can be completely broken.

• First problem: What does it mean for an encryption scheme to be secure?

Page 8: Shift Cipher - UMD

Recall our setting

Sender Receiver

𝑐 ← 𝐸𝑛𝑐𝑘(𝑚)

𝑘 𝑘

c

𝑚 = 𝐷𝑒𝑐𝑘(𝑐)

Page 9: Shift Cipher - UMD

Coming up with the right definition

After seeing various encryption schemes that are clearly not secure, can we formalize what it means to for a private key encryption scheme to be secure?

Page 10: Shift Cipher - UMD

Coming up with the right definition

First Attempt:

“An encryption scheme is secure if no adversary can find the secret key when given a ciphertext”

Problem: The aim of encryption is to protect the message, not the secret key.

Ex: Consider an encryption scheme that ignores the secret key and outputs the message.

Page 11: Shift Cipher - UMD

Coming up with the right definition

Second Attempt:

“An encryption scheme is secure if no adversary can find the plaintext that corresponds to the ciphertext”

Problem: An encryption scheme that reveals 90% of the plaintext would still be considered secure as long as it is hard to find the remaining 10%.

Page 12: Shift Cipher - UMD

Coming up with the right definition

Third Attempt:

“An encryption scheme is secure if no adversary learns meaningful information about the plaintext after seeing the ciphertext”

How do you formalize learns meaningful information?

Page 13: Shift Cipher - UMD

Coming Up With The Right Definition

How do you formalize learns meaningful information?

Two ways:

• An information-theoretic approach of Shannon (next couple of lectures)

• A computational approach (the approach of modern cryptography)

Page 14: Shift Cipher - UMD

New Topic: Information-Theoretic Security

Page 15: Shift Cipher - UMD

Probability Background

Page 16: Shift Cipher - UMD

Terminology

• Discrete Random Variable: A discrete random variable is a variable that can take on a value from a finite set of possible different values each with an associated probability.

• Example: Bag with red, blue, yellow marbles. Random variable X describes the outcome of a random draw from the bag. The value of X can be either red, blue or yellow, each with some probability.

Page 17: Shift Cipher - UMD

More Terminology • A discrete probability distribution assigns

a probability to each possible outcomes of a discrete random variable. – Ex: Bag with red, blue, yellow marbles.

• An experiment or trial (see below) is any procedure that can be infinitely repeated and has a well-defined set of possible outcomes, known as the sample space. – Ex: Drawing a marble at random from the bag.

• An event is a set of outcomes of an experiment (a subset of the sample space) to which a probability is assigned – Ex: A red marble is drawn. – Ex: A red or yellow marble is drawn.

Page 18: Shift Cipher - UMD

Conditional Probability

• A conditional probability measures the probability of an event given that (by assumption, presumption, assertion or evidence) another event has occurred.

• Probability of event 𝑋, conditioned on event 𝑌: Pr[𝑋|𝑌]

• Example: Probability the second marble drawn will be red, conditioned on the first marble being yellow.

Page 19: Shift Cipher - UMD

Basic Facts from Probability

• If two events are independent if and only if Pr[𝑋|𝑌] = Pr[𝑋].

• AND of two events: Pr 𝑋 ∧ 𝑌 = Pr 𝑋 ⋅Pr[𝑌|𝑋]

• AND of two independent events: Pr 𝑋 ∧ 𝑌 =Pr 𝑋 ⋅ Pr[𝑌]

• OR of two events: Pr 𝑋 ∨ 𝑌 ≤ Pr[𝑋] +Pr[𝑌] – This is called a “union bound.”

Page 20: Shift Cipher - UMD

Formally Defining a Symmetric Key Encryption Scheme

Page 21: Shift Cipher - UMD

Syntax • An encryption scheme is defined by three algorithms

– 𝐺𝑒𝑛, 𝐸𝑛𝑐, 𝐷𝑒𝑐

• Specification of message space 𝑴 with 𝑴 > 1. • Key-generation algorithm 𝐺𝑒𝑛:

– Probabilistic algorithm – Outputs a key 𝑘 according to some distribution. – Keyspace 𝑲 is the set of all possible keys

• Encryption algorithm 𝐸𝑛𝑐: – Takes as input key 𝑘 ∈ 𝑲, message 𝑚 ∈ 𝑴 – Encryption algorithm may be probabilistic – Outputs ciphertext 𝑐 ← 𝐸𝑛𝑐𝑘(𝑚) – Ciphertext space 𝑪 is the set of all possible ciphertexts

• Decryption algorithm 𝐷𝑒𝑐: – Takes as input key 𝑘 ∈ 𝑲, ciphertext 𝑐 ∈ 𝑪 – Decryption is deterministic – Outputs message 𝑚 ≔ 𝐷𝑒𝑐_𝑘(𝑐)

Page 22: Shift Cipher - UMD

Distributions over 𝐾,𝑀, 𝐶

• Distribution over 𝑲 is defined by running 𝐺𝑒𝑛 and taking the output. – For 𝑘 ∈ 𝑲, Pr 𝐾 = 𝑘 denotes the prob that the key output by 𝐺𝑒𝑛 is equal to 𝑘.

• For 𝑚 ∈ 𝑴, Pr[𝑀 = 𝑚] denotes the prob. That the message is equal to 𝑚. – Models a priori knowledge of adversary about the message. – E.g. Message is English text.

• Distributions over 𝑲 and 𝑴 are independent. • For 𝑐 ∈ 𝑪, Pr[𝐶 = 𝑐] denotes the probability that the

ciphertext is 𝑐. – Given 𝐸𝑛𝑐, distribution over 𝑪 is fully determined by the

distributions over 𝑲 and 𝑴.

Page 23: Shift Cipher - UMD

Definition of Perfect Secrecy

• An encryption scheme (𝐺𝑒𝑛, 𝐸𝑛𝑐, 𝐷𝑒𝑐) over a message space 𝑴 is perfectly secret if for every probability distribution over 𝑴, every message 𝑚 ∈ 𝑴, and every ciphertext 𝑐 ∈ 𝑪 for which Pr 𝐶 = 𝑐 >0:

Pr 𝑀 = 𝑚 𝐶 = 𝑐] = Pr[𝑀 = 𝑚] .

Page 24: Shift Cipher - UMD

An Equivalent Formulation

• Lemma: An encryption scheme (𝐺𝑒𝑛, 𝐸𝑛𝑐, 𝐷𝑒𝑐) over a message space 𝑴 is perfectly secret if and only if for every probability distribution over 𝑴, every message 𝑚 ∈ 𝑴, and every ciphertext 𝑐 ∈ 𝑪:

Pr 𝐶 = 𝑐 𝑀 = 𝑚] = Pr[𝐶 = 𝑐] .

Page 25: Shift Cipher - UMD

Basic Logic

• Usually want to prove statements like 𝑃 →𝑄(“if 𝑃 then 𝑄”)

• To prove a statement 𝑃 → 𝑄we may:

– Assume 𝑃 is true and show that 𝑄 is true.

– Prove the contrapositive: Assume that 𝑄 is false and show that 𝑃 is false.

Page 26: Shift Cipher - UMD

Basic Logic

• Consider a statement 𝑃 ↔ 𝑄(𝑃 if and only if 𝑄)

– Ex: Two events 𝑋, 𝑌are independent if and only if Pr 𝑋 ∧ 𝑌 = Pr 𝑋 ⋅ Pr 𝑌 .

• To prove a statement 𝑃 ↔ 𝑄it is sufficient to prove:

– 𝑃 → 𝑄

– 𝑄 → 𝑃

Page 27: Shift Cipher - UMD

Proof (Preliminaries)

• Recall Bayes’ Theorem:

– Pr 𝐴 𝐵] =Pr 𝐵|𝐴 ⋅Pr[𝐴]

Pr[𝐵]

• We will use it in the following way:

– Pr 𝑀 = 𝑚 𝐶 = 𝑐] =Pr 𝐶=𝑐 𝑀=𝑚]⋅Pr[𝑀=𝑚]

Pr[𝐶=𝑐]

Page 28: Shift Cipher - UMD

Proof

Proof: →

• To prove: If an encryption scheme is perfectly secret then

“for every probability distribution over 𝑴, every message 𝑚 ∈ 𝑴, and every ciphertext 𝑐 ∈ 𝑪:

Pr 𝐶 = 𝑐 𝑀 = 𝑚] = Pr[𝐶 = 𝑐] . "

Page 29: Shift Cipher - UMD

Proof (cont’d)

• Fix some probability distribution over 𝑴, some message 𝑚 ∈ 𝑴, and some ciphertext 𝑐 ∈ 𝑪.

• By perfect secrecy we have that

Pr 𝑀 = 𝑚 𝐶 = 𝑐] = Pr[𝑀 = 𝑚] .

• By Bayes’ Theorem we have that:

Pr 𝑀 = 𝑚 𝐶 = 𝑐] =Pr 𝐶 = 𝑐 𝑀 = 𝑚] ⋅ Pr[𝑀 = 𝑚]

Pr[𝐶 = 𝑐]= Pr[𝑀 = 𝑚] .

• Rearranging terms we have: Pr 𝐶 = 𝑐 𝑀 = 𝑚] = Pr[𝐶 = 𝑐] .