Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Lectures_SSD2_Yermakova / Lectures_SSD2 Yermakova.doc
Скачиваний:
226
Добавлен:
25.02.2016
Размер:
3.16 Mб
Скачать

Substitution Cipher

The most basic type of private key encryption is the substitution cipher. A substitution cipher changes the plaintext to ciphertext by replacing each element of the plaintext with its encrypted substitute. The elements might be individual letters, but they could also be words or phrases. Probably the simplest of all substitution ciphers is the character-shift cipher, which substitutes letters based on their position in the alphabet. For example, if we replace each letter of the plaintext with the letter that occurs after it in the alphabet, then A becomes B, E becomes F, and so forth. And, for completeness, we'll say that Z becomes A. The "key" in a character-shift cipher is the number of positions to shift each letter, and the direction in which to shift. If you know the key, you can decrypt the message by shifting the ciphertext characters in the opposite direction. This recovers the plaintext.

Message

Encryption Technique

Encrypted Message

HELLO WORLD

shift right by one character

IFMMP XPSME

IBM

shift left by one character

HAL

Table 1 Substitution encryption results

The character-shift cipher, because it is so simple, only provides for a small number of possible ways to encrypt a message. How many ways? Notice that shifting left by one character is the same as shifting right by 25 characters. Therefore, we only need to consider shifts in one direction. And, shifting by 26 characters would amount to no encryption at all, since A would be replaced by A, etc. So, there are only 25 distinct shifts, or 25 possible keys. This coding scheme therefore has a very small keyspace. The following chart shows all 25 character-shifts.

Original Letter

Right Character Shift

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

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

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

A

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

B

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

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

D

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

A

B

C

D

E

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

A

B

C

D

E

F

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

A

B

C

D

E

F

G

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

J

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

J

K

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

J

K

L

N

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

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

N

P

Q

R

S

T

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

Q

R

S

T

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

R

S

T

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

S

T

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

T

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

W

X

Y

Z

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

X

Y

Z

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

Y

Z

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Z

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

Table 2 Simple shift-substitution

While this may look like a pretty complicated table, a computer can instantly calculate all 25 decodings of a message and then pick the decoding that produces recognizable English words. This method of trying every possible key to break a code is called a brute force attack, and is highly effective on codes with small keyspaces.

Since simple codes can be broken quickly by brute force, one essential component to a secure code is a large keyspace. Let us see how we can increase the keyspace for a substitution cipher. Suppose that instead of shifting each character of plaintext by the same amount, we instead used a secret password, or even better, a passphrase, as our encryption key. The letters of the passphrase can be used one at a time to tell us how many characters to shift the corresponding plaintext letter by. For example, if the passphrase is CAT, we note that the letters C-A-T have alphabetic positions 3-1-20. We will therefore shift the first letter of plaintext by three characters, the second letter by one character, and the third letter by twenty characters. If we are encrypting a long message, we can repeat the passphrase in order to make its length match the plaintext.

Plaintext

HELLO WORLD

Key

CAT

Copied Key

CATCA TCATC

Key Converted to Numbers

Plaintext

3 1 20 3 1 20 3 1 20 3

H E L L O W O R L D

Ciphertext

K F F O P Q R S F G

Table 3 Passphrase key encryption

Using a passphrase to control the substitution cipher greatly expands the keyspace. With a passphrase n letters long, the keyspace is of size 26n, which grows very quickly with n. An eight-letter passphrase provides for over 208 billion possible keys.