You are on page 1of 20

Cryptography

Classic
Data Encryption

Content

Content
Basic Terminology
Introduction
Symmetric Cipher
Caesar Cipher
Base 64 encoding
Monoalphabetic Cipher
Playfair Cipher
Hill Cipher
Vigenre Cipher
Rail Fence Cipher
Row Transposition Cipher
Product Cipher
Base 64 Encoding Table

Page
3
4
5
7
8
9
13
15
17
18
18
19
20

Basic terminology
Plaintext
Ciphertext
Enciphering or encryption

=
=
=

Encryption algorithm

Deciphering or decryption
Decryption algorithm

=
=

Secret key

Cryptography

Cryptography system

Cipher

Block cipher

Stream cipher

Cryptanalysis
Brute force attack

=
=

Key space

original message to be encrypted


the encrypted message
the process of converting plaintext into
ciphertext
The sequence of data processing steps
that go into transforming plaintext into
ciphertext.
- two inputs: a plaintext, secret key
recovering plaintext from ciphertext
The sequence of data processing steps go
that into transforming ciphertext back
into plaintext.
- two inputs: a ciphertext, secret key
same key used for encryption and
decryption
- Also referred as a symmetric key
the many schemes available today
for encryption and decryption
any single scheme for encryption and
decryption
a cipher means the same thing as a
cryptographic system
a block cipher processes a block of input
data at a time and produces a ciphertext
block of the same size
a stream cipher encrypts data on the fly,
usually one byte at a time
means breaking the code
means trying every possible key on a piece
of ciphertext until an intelligible translation
into plaintext is obtained
the total number of all possible keys that
can be used in a cryptographic system

Introduction
Encryption is the conversion of data into a form, called a ciphertext, that cannot
be easily understood by unauthorized people. Decryption is the process of
converting encrypted data back into its original form, so it can be understood.
The use of encryption/decryption is as old as the art of communication. In
wartime, a cipher, often incorrectly called a code, can be employed to keep
the enemy from obtaining the contents of transmissions. (Technically, a code is a
means of representing a signal without the intent of keeping it secret; examples
are Morse code and ASCII.) Simple ciphers include the substitution of letters for
numbers, the rotation of letters in the alphabet, and the "scrambling" of voice
signals by inverting the sideband frequencies. More complex ciphers work
according to sophisticated computer algorithms that rearrange the data bits in
digital signals.
In order to easily recover the contents of an encrypted signal, the correct
decryption key is required. The key is an algorithm that undoes the work of the
encryption algorithm. Alternatively, a computer can be used in an attempt to
break the cipher. The more complex the encryption algorithm, the more difficult
it becomes to eavesdrop on the communications without access to the key.
Here I would like to introduce some of the classic encryption:

Symmetric Cipher
A symmetric cipher model

Example (symmetric-key encryption)


Let A = {A,B,C,..,X,Y,Z} be the English Alphabet
Let m and c to be the set of all strings (words) of length five over A.
To encrypt, an English message is broken up into groups each having five letters
(with appropriate padding if the length of the message is not a multiple of five)
A permutation(change) e is applied to each letter one at a time.
To decrypt, the inverse permutation d = e-1 is applied to each letter of ciphertext.
For instance, supposed that the key e is chosen to be the permutation which
maps each letter to the one which is three position to its right, as shown:
(

A message
plain text = THIS CIPHER IS CERTAINLY NO SECURE.
m = THISC IPHER ISCER TAINL YNOTS ECURE group it into five
is encrypted to
c = Ee = WKLVF LSKHU LVFHU WDLQO BQRWV HFXUH
Ciphertext = wklvflskhulvfhuwdlqobqrwvhfxuh
Explanation:

c = ciphertext
E = encryption algorithm
d = decryption algorithm

Two requirements for secure use of symmetric encryption:


a. a strong encryption algorithm
b. a secret key known only to sender / receiver
c = Ek (m)
m = Dk (c)
Implies a secure channel to distribute key
Cryptography can characterize by:
a. type of encryption operations used
- substitution / transposition / product
b. number of keys used
- single key or private / two key or public
c. way in which plaintext is processed
- block / stream
Mathematically:
Y = EK(X)
X = DK(Y)

or
or

Y = E(K, X)
X = D(K, Y)

X = plaintext
Y = ciphertext
K = secret key
E = encryption algorithm
D = decryption algorithm
Both E and D are known to public

Substitution Ciphers
Replacing each element of the plaintext with another element
Shift ciphers
Base64 encoding
Monoalphabetic ciphers
Playfair cipher
The Hill cipher
Polyalphabetic ciphers

Shift Ciphers

Caesar cipher

This is the earlier known example of a substitution cipher.


invented by Julius Caesar
First attested use in military affairs
Replacing each letter of the plaintext by a shifted letter
in the alphabet used.
- If the shift value is (3) then we can define
transformation as:
- e.g : plaintext : meet me after toga party
ciphertext : PHHW PH DIWHU WKH WRJD SDUWB
- If we represent each letter of the alphabet by an
integer that corresponds to its position in the alphabet,
such as:
a, b, c, ..., x, y, z
0, 1, 2, ..., 23, 24, 25
The formula for placing each character p of the
plaintext with a character c of the ciphertext can be
expressed as:
( ) (
)
Where E() stands for encryption.
The
operator returns the integer remainder of the
) is divided by 26, the number of
division when (
letters in the English alphabet assuming case-insensitive
- A more general version of this cipher that allows for any
degree of shift would be expressed by
( ) (
)
- The formula for decryption would be
( ) (
)
- k = secret key, E() = encryption, D() = decryption
7

base64 encoding
- A simple substitution cipher obviously looks much too
simple to be able to provide any security, but that is the
case only if you have some idea regarding the nature
of plaintext
- For example, in the plaintext Man , encoded in ASCII
the character M, a and n are stored as bytes 77, 97
and 110 which are the 8-bit binary values 01001101,
01100001 and 01101110. These three values are joined
together into a 24-bit string, producing
010011010110000101101110. Group of 6-bits (6 bits have
a maximum of 26 = 64 different binary values) are
converted into individual numbers from left to right (in
this case, there are four numbers in a 24-bit string),
which are then converted into their corresponding
Base64 character values.
Text content
M
a
n
77 (0x4d)
97 (0x61)
110 (0x6e)
ASCII
Bit pattern 0 1 0 0 1 1 0 1 0 1 1 0 0 0 0 1 0 1 1 0 1 1 1 0
19
22
5
46
Index
Base64-encoded
T
W
F
u

- The table of this encoding will be shown at the Base 64


Encoding Table section.

monoalphabetic ciphers
- Basically, Caesar cipher is also a kind of
monoalphabetic ciphers. In monoalphabetic ciphers,
we have a substitution rule that gives us a replacement
ciphertext letter for each letter of the alphabet used in
the plaintext message.
- Lets now consider a seemingly strong monoalphabetic
cipher by making our substitution letters a random
permutation of the 26 letters of the alphabet:

- The encryption key is now the sequence of substitution


letters. In other words, the key in this case is the actual
random permutation of the alphabet used.
- Since there are 26! permutations of the alphabet, we
end up with an extremely large key space. The number
26! is much larger than 4 x 1026. Since each permutation
constitutes a key, that means that the monoalphabetic
cipher has a key space of size more than 4 x 1026.
- With this extremely large key space, you might think
that it is secure. You are WRONG. There is language
characteristic problems.

Language Statistic and Cryptanalysis


on Monoalphabetic ciphers
- A very large key space of a monoalphabetic
cipher means that the total number of all possible
keys that would need to be guessed in a pure
brute-force attack would be much too large for
such an attack to feasible.
- Obviously, this would rule out a brute-force attack.
Even if each key took only a nanosecond to try, it
would still take zillions of year to try out even half
the keys.
- However if you know the nature of plaintext if it is a
plain English, it can be broken easily with a
statistical attack. In plain English, letters in a text
are not equally commonly use.
- Using frequency distribution for single characters,
for pair of characters, for triple of characters and
comparing those with similar statistics for English.

10

- In decreasing order of frequencies :


Double letters :
th he an in er re es on
Triple letters :
the and ent ion tio for nde
- Key concept : monoalphabetic substitution does
not change relative letter frequencies.
- To attack, we must calculate the letters
frequencies for ciphertext and next compare this
distribution against the known one.
- For example:
UZQSOVUOHXMOPVGPOZPEVSGZWSZOPFPESXUDBMETSXAIZ
VUEPHZHMDZSHZOWSFPAPPDTSVPQUZWYMXUZUHSX
EPYEPOPDZSZUFPOMBZWPFUPZHMDJUDTMOHMQ

- Step 1: count relative letters frequencies


P 13.33

H 5.83

F 3.33

B 1.67

C 0.00

Z 11.67

D 5.00

W 3.33

G 1.67

K 0.00

8.33

E 5.00

Q 2.50

Y 1.67

L 0.00

8.33

V 4.17

2.50

0.83

N 0.00

7.50

X 4.17

1.67

0.83

R 0.00

6.67

- Step 2 : As P has the highest frequency in the


ciphertext and it can be map with E if compare
with the distribution of the known one. The same
thing occurs by mapping T on Z.
- Step 3 : Of double letters, ZW has the highest
frequency, so guess ZW can be mapped with th
and hence ZWP can be mapped by the

11

- Step 4 :Proceeding with trial and error and finally


get:
it was disclosed yesterday that several informal but
direct contacts have been made with political
representatives of the viet cong in moscow

12

Playfair ciphers
- With one character at a time substitution obviously
leaves too much of the plaintext structure in ciphertext.
- So how about destroying some of that structure by
mapping multiple characters at a time to ciphertext
characters?
- In Playfair cipher, you first choose an encryption key.
You then enter the letters of the key in the cells of a 5
5 matrix in a left to right fashion starting with the first cell
at the top-left corner. You fill the rest of the cells of the
matrix with the remaining letters in alphabetic order. In
the following example, the key is playfair example:
P
L
A
Y
F
I
R
E
X
M
B
C
D
G
H
K
N
O
Q
S
T
U
V
W
Z
- Plaintext is encrypted two letters at a time.
- If a pair is repeated letter, insert a filter like X, e.g.
Communication encrypts as Co mx mu ni ca ti on
- If the letters appear on the same row of your table,
replace them with the letters to their immediate right
respectively (wrapping around to the left side of the
row if a letter in the original pair was on the right side of
the row).
e.g. XM becomes MI
- If the letters appear on the same column of your table,
replace them with the letters immediately below
respectively (again wrapping around to the top side of
the column if a letter in the original pair was on the
bottom side of the column). e.g. NU becomes UL

13

- Otherwise, each letter is replaced by the letter in the


same row but in the column of the other letter of the
pair.
e.g. TH becomes ZB
- To decrypt, use the INVERSE (opposite) of the last 3 rules,
and the 1st as is (dropping any extra "X"s that don't
make sense in the final message when you finish).
- Example :
Plaintext : Hide the gold in the tree stump
Ciphertext : BM OD ZB XD NA BE KU DM UI XM MO UV IF
- Compared to a monoalphabetic cipher with 26
character, a playfair cipher would be more secured
with 26 x 26 = 676 characters

14

the hill ciphers


- The Hill cipher takes a very different (more
mathematical) approach to multi-letter substitution, as
we describe in what follows.
- You assign an integer to each letter of the alphabet.
For the sake of discussion, lets say that you have
assigned the integers 0 through 25 to the letters a
through z of the plaintext.
- The encryption key, call it k, consists of a 33 matrix of
integers:
(

- Now we can transform three letters at a time from the


plain- text, the letters being represented by the
numbers p1, p2, and p3, into three ciphertext letters c1,
c2, and c3 in their numerical representations by
( )

)(

- Therefore, the mathematical model is


( )
( )
k is the key matrix and k-1 is the matrix inverse.
- Encryption Example : Plaintext : pay
key : (

15

( )

)(

- Ciphertext : LNS
- Decryption Example :
key :

inverse key :

)(

16

Polyalphabetic Ciphers
:
Vigenre cipher
- In a poly alphabetic cipher, on the other hand, the
substitution rule changes continuously from one
character position to the next in the plaintext
according to the elements of the encryption key.
- In the Vigenere cipher, you first align the encryption
key with the plaintext message. ( If the plaintext
message is longer than the encryption key, you can
repeat the encryption key, as I show below where the
encryption key is lemon.) Now consider each letter of
the encryption key denoting a shifted Caesar cipher,
the shift corresponding to the letter of the key.
- E.g. :

Transposition cipher
rail fence cipher
row transposition cipher

17

transposition cipher :

rail fence cipher

- Using this cipher, one should write message letters


out diagonally over a number of rows.
- After that, just read or write off cipher row by row.
- It is not that secure.
- E.g. plaintext : railfencecipher
written : r i f n e i h r
a l e c c p e
ciphertext : rifneihraleccpe

transposition cipher :

row transposition cipher

- It is a more complex scheme compared with rail


fence cipher.
- First, you should write out letters of message out in
rows over a specified number of columns
- then reorder the columns according to some key
before reading off the columns.
- key :
4 3 1 2 5 6 7
- Plaintext :
a t t a c k p
o s t p o n e
d u n t i l t
wo amx y z
- ciphertext
:ttna aptm tsuo aodw coix knly petz

18

Products Cipher
- Ciphers using substitutions or transpositions are not
secure because of language characteristic.
- Hence, consider using several ciphers in succession
to make harder :
o Two substitutions make a more complex
substitution
o Two transposition make a more complex
transposition
o A substitution followed by a transposition
makes a new much harder cipher

19

base 64 encoding table

Value Char Value Char Value Char Value Char


0
A
16
Q
32
g
48
w
1
B
17
R
33
h
49
x
2
C
18
S
34
i
50
y
3
D
19
T
35
j
51
z
4
E
20
U
36
k
52
0
5
F
21
V
37
l
53
1
6
G
22
W
38
m
54
2
7
H
23
X
39
n
55
3
8
I
24
Y
40
o
56
4
9
J
25
Z
41
p
57
5
10
K
26
a
42
q
58
6
11
L
27
b
43
r
59
7
12
M
28
c
44
s
60
8
13
N
29
d
45
t
61
9
14
O
30
e
46
u
62
+
15
P
31
f
47
v
63
/

20

You might also like