Encryption
1
L e a rn in g o b je c tiv e s
Define encryption
Explain how Caesar and Vernam cyphers work
Compare Vernam and Caesar cypher
Explain symmetric and asymmetric encryption with public and private key
Explain hashing and its applications for storing passwords and checksums
2
Keywords
Encryption – scrambling a message from its original plaintext into cyphertext using
some function with a key.
Decryption – converting the cyphertext into plaintext using some function with a key
Plaintext – the original message
cyphertext – the encrypted message
Key – A string of characters needed to encrypt and decrypt a message
Cryptoanalysis - cracking encrypted messages without the key
Encryption
When transferring sensitive information from one place to another it
is necessary to encrypt the message.
Given enough time, the cyphertext and computational power nearly
all methods of encryption can be cracked using cryproanalysis
although the problem may be intractable
Only the Vernam cypher has proven to be unbreakable.
C a e s a rc y p h e r
The Caesar cypher is a shift substitution cypher
It works by replacing a letter with another letter that is shifted along in the
alphabet by a set number of places
The key is a letter and lets us know the number of letters we shift the
alphabet by
For instance, a key of E means that we would shift by 4 places.
5
C a e s a rc y p h e r-E n c ry p tio n
In the example below we are using a key W so Z A B
Y
we shift by 22 places to the left. X VW X C
T U Y
D
To encrypt we go through each letter in the S
E
V
plaintext finding the letter on the outer ring and
Q N O P Q R
A B
S T U
F G H I
replacing it with the corresponding letter on the
C D E
inner ring
For instance we wish to encrypt the word
M
MARCH. The first letter M on the outer ring
F
L G
J
HI
corresponds to the letter I on the inner ring J K K
P
O
L M
The plaintext MARCH is encrypted as IWNYD N
C a e s a rc y p h e r-D e c ry p tio n
To decrypt the message we reverse the process. Z A B
Y
We go through each letter in the cyphertext
X VW X C
T U Y
D
finding the letter on the inner ring and replacing S
E
V
it with the corresponding letter on the outer ring
Q N O P Q R
A B
S T U
F G H I
For instance we wish to encrypt the word
C D E
MARCH. The first letter M on the outer ring
corresponds to the letter I on the inner ring
M
The cyphertext XASWNA would bedecrypted as
F
L G
J
HI
BEWARE J K K
P
O
L M
N
C ry p to a n a ly s is o fC a e s a rc y p h e r
The Caesar cypher is not a secure method of encryption and is easy to crack
using two methods.
You could try all 26 shifts and apply it to the cypher text. When you have a
sensible plaintext message then you have cracked the encryption and found the
key.
If you had a long enough piece of cyphertext you could use frequency analysis of
letters. E is the most commonly used letter, so the most commonly occurring
letter in the cyphertext will likely correspond to E in the plaintext.
You match up the E on the inner wheel with the most frequently occurring letter
on the outer wheel and perform the decryption
8
Cut out the wheels below to create your own Caesar cypher
Y Z A B
VW X C
T U Y X
W
S
D
Z
O P Q R
E
V
A B
F
C D E
G H
S
N
M
I
L G
K HI
J
J
P K
O
L M
N
E x e rc is e s
1. Using a key of H encrypt the following word “IDES”
2. Using a key of M encrypt the following word “BRUTUS”
3. Using a key of B decrypt the following cyphertext “SPNBO”
4. Using a key of Z encrypt your name
5. Using crypto analysis decrypt the following cyphertext “XIZWIG”.
6. Why can you not use frequency analysis to solve this problem?
7. What happens if you have a key of A?
8. What happens if you have a shift of -3? What is the corresponding key?
9. Encrypt a short message with any key. Send the encrypted message to someone else
with the key and see if they can decrypt it.
10
E x e rc is e s
1. Using a key of H encrypt the following word “IDES” PKLZ
2. Using a key of M encrypt the following word “BRUTUS” NDGFGE
3. Using a key of B decrypt the following cyphertext “SPNBO” ROMAN
4. Using a key of Z encrypt your name?
5. Using crypto analysis decrypt the following cyphertext “XIZWIG” JULIUS
6. Why can you not use frequency analysis to solve this problem? cyphertext is too
short
7. What happens if you have a key of A? No encryption occurs, as plain text is the
same as the cypher text.
8. What happens if you have a shift of -3? What is the corresponding key? X
11
Use cryptoanalysis to break the following
cyphertext
fvbdpssulclyulclyjyhjraopzj
vklpmfvbkvaolufvbtbzailzvt
lrpukvmnlupbz
STEPS
1. Perform frequency analysis: Add up each of the letters.
2. Assign the most frequently occurring cyphertext letter to correspond to the plaintext
letter E
3. Line up the outer and inner wheels of the Caesar cypher wheel such that the outer
wheel E corresponds the most frequently occurring letter in the cyphertext on the
inner wheel
4. Convert each letter from the cyphertext to the corresponding plain text
Clue: l is the most frequently occurring letter
12
Solution: Use cryptoanalysis to break the following
code
fvbdpssulclyulclyjyhjraopzj
vklpmfvbkvaolufvbtbzailzvt
lrpukvmnlupbz
youwillnevernevercrackthiscodeifyou
dothenyoumustbesomekindofgenius
13
V e rn a m (o n e -tim e p a d )c y p h e r
With a Vernam cypher we have perfect security. It is the only cypher that has proven
impossible to break using cryptoanalysis. To help achieve this the Vernam cypher has
three features:
The key is only used once
The length of the key is at least long as the message that we want to send.
It is truly random
Its principal disadvantage is that the key needs to be shared with the recipient
15
W o rk e d E x a m p le :V e rn a m c y p h e rE n c ry p tio n
We wish to encrypt the letter word “Hello”.
Converting from ASCII to binary this is: XOR table
1001000 1100101 1101100 1101100 1101111 Input 1 Input 2 Output
0 0 0
Our random key is !d7sY which in binary is: 1 0 1
0 1 1
0100001 1100100 0110111 1110011 1011001
1 1 0
Apply a bitwise XOR between the corresponding pairs of letters.
Plain Text Hello 1001000 1100101 1101100 1101100 1101111
Key !d7sY 0100001 1100100 0110111 1110011 1011001
cyphertext 1101001 0000001 1011011 0011111 0110110
W o rk e d E x a m p le :V e rn a m c y p h e rD e c ry p tio n
To decrypt we apply the XOR operator to the cypher text and the
same key to get back the plain text.
XOR table
Input 1 Input 2 Output
As before we a bitwise XOR between the corresponding pairs of 0 0 0
letters.
1 0 1
0 1 1
1 1 0
cyphertext 1101001 0000001 1011011 0011111 0110110
Key !d7sY 0100001 1100100 0110111 1110011 1011001
Plain Text Hello 1001000 1100101 1101100 1101100 1101111
ASCII Binary
A 1000001 N 1001110
1. Decrypt the following using Caesar B 1000010 O 1001111
cypher with a shift of 5 (key=F): H T C 1000011 P 1010000
QTXXJZR D 1000100 Q 1010001
E 1000101 R 1010010
F 1000110 S 1010011
G 1000111 T 1010100
2. Use Vernam Cypher to encode in bits
H 1001000 U 1010101
the message CAT with the key GHX I 1001001 V 1010110
J 1001010 W 1010111
K 1001011 X 1011000
3. What is the plaintext bit pattern L 1001100 Y 1011001
when out cyphertext is ABC and our M 1001101 Z 1011010
key is DEF
18
ASCII Binary
A 1000001 N 1001110
1. Decrypt the following using Caesar cypher B 1000010 O 1001111
with a shift of 5 (key=F): H T Q T X X J Z R C 1000011 P 1010000
COLOSSEUM D 1000100 Q 1010001
E 1000101 R 1010010
F 1000110 S 1010011
2. Use Vernam Cypher to encode in bits the G 1000111 T 1010100
message CAT with the key GHX H 1001000 U 1010101
Plaintext CAT 1000011 1000001 1010100 I 1001001 V 1010110
Key GHX 1000111 1001000 1011000 J 1001010 W 1010111
K 1001011 X 1011000
Cyphertext 0000100 000100 1 0001100
L 1001100 Y 1011001
M 1001101 Z 1011010
3. What is the plaintext bit pattern when out
cyphertext is ABC and our key is DEF
Cyphertext ABC 1000001 1000010 1000011
Key DEF 1000100 1000101 1000110
Plaintext 0000101 0000111 0000101 19
S y m m e tric e n c ry p tio n
Both Vernam and Caesar Cypher use symmetric encryption
With symmetric encryption, both the sender and receiver use the same key to encrypt the decrypt the
data.
Encryption:
Decryption
Where
cyphertext
is the plaintext message,
is the key, 20
is the symmetric encryption algorithm (eg Vernam or Caesar cypher)
S y m m e tric e n c ry p tio n
RECEIVER
SENDER Encrypt message
with cypher Decrypt message
Plaintext message, Send cyphertext, c using inverse
algorithm f using
p key K cypher function f-1
using key
What might be the limitations of using symmetric encryption for
communications over the internet?
How can you ensure only the sender and receiver have the key and no
one else?
A s y m m e tric E n c ry p tio n
For asymmetric encryption two keys are needs: One to encrypt the message and the other to decrypt
the message
This is a one-way function meaning that you cannot use the same key to encrypt and decrypt the data.
Steps
1) The receiver sends out their public key, .
2) The sender encrypts the plaintext message using the cypher function and the receiver’s public key,
Encryption:
3) The cyphertext message is sent
4) The receiver then decrypts the message using the inverse cypher function and private key, that they
do not share with anyone Decryption:
A s y m m e tric E n c ry p tio n
Alice wants to send a message to Bob.
Alice uses Bob’s public key that is made available to everyone to encrypt the message.
Alice then sends the encrypted message to Bob
Bob decrypts the message using his own private key that is known only to him.
To reply Bob uses Alice’s public key to encrypt his message. Bob sends the message
and Alice decrypts the message using Alice’s private key.
RECEIVER (Bob)
Encrypt message Decrypt message
SENDER (Alice) with cypher using inverse
Plaintext message, algorithm f using Send cyphertext, c cypher function f-1
p key Kpu (receiver’s using key Kpr
public key) (receiver’s public
key)
23
H a s h in g
Hashing like encryption scrambles some input, but unlike encryption
there is no way to perform the reverse operation and unscramble to
retrieve the original message.
Used for storing passwords and allowing access to systems
A user enters a password that is then hashed. The hashed password
is them compared against the stored password for the user. If both
are the same then the user has entered the correct password and can
now access the system
C h e c k s u m
Checksums are often use when downloading data over the internet,
to check whether the data have been corrupted during transfer.
Checksums are a hashing applied to the data.
Checksums are downloaded alongside the data.
The hashing is applied again to the data once it has been downloaded
to create a second checksum
The two checksums are compared. They should both be the same if
the data are uncorrupted.
E x te n s io n ta s k s
1) Find out about:
Substitution cypher
Transposition cypher
Vignere cypher
RSA encryption
2) Now code up some of the encryption algorithms.
26
H o m e w o rk :C a e s a rC y p h e r
Code up a Casear cypher.
Use ord() and chr() functions to help you.
Remember that ASCII characters are in order eg A=65, B=66 and so on.
Use either lowercase or uppercase not both.
Do both encryption and decryption
Extension 1: Use cryptoanalysis to decrypt a message trying all 25 keys
Extension 2: Use frequency analysis to decrypt the message.
Extension 3: Add a GUI
27