S03 Secret Key Encryption
S03 Secret Key Encryption
Introduction
• Encryption is the process of encoding a message in such a way that
only authorized parties can read the content of the original message
• Two types of encryption
• secret-key encryption : same key for encryption and decryption
• pubic-key encryption : different keys for encryption and decryption
Our goal is to make sure Alice can receive our message securely, and our
original message cannot be intercepted
Bob Alice
Cleartext/Plaintext
“Hi Alice, my address is 123
Painting Avenue. Please
stop by at 6:00”
Eve
Bob Alice
Cleartext/Plaintext
“Hi Alice, my address is 123
Painting Avenue. Please
stop by at 6:00”
Cleartext/Plaintext
“Hi Alice, my address is 123
Painting Avenue. Please
If Eve intercepts our ciphertext, she
stop by at 6:00”
can't do very much with it
MuYGoP5LiTTGPVX6U/
Eve r2VTpxPSqTFmy5nsoFWURThKMh
Hk/
7tbjYsS2EJ917q7megTAcV+V4ZMU
4HjJjiW2DCBroxvJ0V3ZYDgZ8B9lUv
GUmdiRMH25Xkf7QrhAGR3FF
Bob Alice
Cleartext/Plaintext
MuYGoP5LiTTGPVX6U/
“Hi Alice, my address is 123 r2VTpxPSqTFmy5nsoFWURT
Painting Avenue. Please hKMhHk/
7tbjYsS2EJ917q7megTAcV+V
stop by at 6:00” 4ZMU4HjJjiW2DCBroxvJ0V3Z
YDgZ8B9lUvGUmdiRMH25Xk
f7QrhAGR3FF
Eve
Alice receives the ciphertext,
and then uses the same key “Hi Alice, my address is 123
that bob used, and then Painting Avenue. Please
decrypts the ciphertext stop by at 6:00”
The importance here is that
the keys used for
encryption/decryption are
secret (ie not public
knowledge)
Deterministic programs*
Monoalphabetic Substitution
Cipher
Substitution Cipher
• Encryption is done by replacing units of plaintext with ciphertext,
according to a fixed system.
• Units may be single letters, pairs of letters, triplets of letters, mixtures
of the above, and so forth
• Decryption simply performs the inverse substitution.
• Two typical substitution ciphers:
• monoalphabetic - fixed substitution over the entire message – Same “rules”
are applied throughout the entire plaintext
• Polyalphabetic - a number of substitutions at different positions in the
message
Monoalphabetic Substitution Cipher
• Encryption and decryption
Breaking Monoalphabetic
Substitution Cipher
• Frequency analysis is the study of the frequency of letters or groups
of letters in a ciphertext.
• Common letters : T, A, E, I, O
• Common 2-letter combinations (bigrams): TH, HE, IN, ER
• Common 3-letter combinations (trigrams): THE, AND, and ING
Here is a ciphertext (cipher.txt)
Suppose we know that that this message is an english message encrypted with a monolithic substitution cipher
Frequency Analysis leverages the fact that in any given written language, certain letters and
combinations occur more frequently than others
In English, T, A , I, and O are the most common letters, so it is likely the letters that appear the
most frequently in our ciphertext are one of those
Here is a ciphertext (cipher.txt)
We can write a program that counts the frequency of characters (1-gram) and
frequency of character pairs (2-gram)
Translate ciphertext.txt, and replace all y with t, and replace all d with h
Keep adding more characters to your decryption scheme until you get the full answer
Mode of Encryptions
Review the XOR operator:
Message:
⊕ 0001 1010 0011
Key:
1100 1100 0101
1⊕ 0 = 1
Ciphertext:
1101 0110 0110
0⊕0=0
1⊕1=0 How to get original message?
0⊕1=1
Review the XOR operator:
Message:
⊕ 0001 1010 0011
Key:
1100 1100 0101
1⊕ 0 = 1
Ciphertext:
⊕ 1101 0110 0110
0⊕0=0
1⊕1=0
1100 1100 0101
0001 1010 0011
0⊕1=1
XOR with the
key again!
Block Cipher
Split in messages into fixed sized blocks, encrypt each block
separately
Notice: For the same key, a plaintext always maps to the same ciphertext
In ECB (Electronic Codebook) mode, each block of plaintext is encrypted
separately. This means that the encryption of one block does not depend on
any other blocks.
Electronic Codebook (ECB) Mode
• Using openssl enc command:
3
plain.txt
Using OpenSSL to encrypt w/ ECB