You are on page 1of 12

Information Security

Lab1: Introduction to Cryptography

Instructor: Eng. Khalil Alkhateeb & Eng. Manal Alomar

Lab Objectives
2

The aim of this lab is to introduce the basic concepts of
cryptography and to familiarize the student with the following
concepts:
Cryptosystems
Cryptanalysis
For better understanding of these concepts, the students are
asked to implement and break the Caesar cipher using the
JAVA programming language.

Cryptography
3
Cryptography: is a compound greek word meaning "secret
writing".
Cryptography involves converting plaintext into ciphertext
through a process known as encryption.
Ciphertext is converted back to plaintext by decryption.
Usually the algorithms are public, but an input, called the key, is
secret.
The key for encryption does not necessarily have to be the
same as the key for decryption.

Cryptosystem & Cryptanalysis
4
Cryptosystem (cipher system) is a five-tuple (P, C, K, E, D):
P: finite set of possible plaintexts.
C: finite set of possible ciphertexts.
K: the key space, finite set of possible keys.
For all k in K, there is an encryption rule e
k
in E and a corresponding
decryption rule d
k
in D.
Each e
k
: P C and d
k
: C P are functions such that d
k
(e
k
(x)) = X for all
plaintext X in P.

Cryptanalysis is recovering a plaintext from a given ciphertext
without knowing the key or recovering the key.

Properties of a Good Cryptosystem
5
Each e
k
function should be efficiently computable.
An opponent, upon seeing the ciphertext string Y should be
unable to determine the key that was used or the plaintext
string X.
An exhaustive key search should be infeasible
the keyspace should be very large.

Types of Cryptosystems
6
Cryptosystems can be broadly classified into:
Symmetric-key systems.
Public-key systems.
A symmetric-key system, or secret-key system :
The sender and the receiver of a message, share a single common key
that is used to encrypt and decrypt messages.
A public-key system uses two keys:
A public key to encrypt the messages.
A private key to decrypt them.

Shift Cipher
7
Shift cipher encrypts ordinary English text by setting up a
correspondence between alphabetic characters and residues
modulo 26 as follows A 0, B1, , Z 25.

Shift Cipher is defined by P = C = K = Z
26
.
For 1 k 25, define
Is this a Cryptosystem?
A B C D E F G H I J K L M
0 1 2 3 4 5 6 7 8 9 10 11 12
N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
Caesar code
8
is a shift cipher code.
The story of the code begins: When Julius Caesar sent messages to his
trusted acquaintances.
He didn't trust the messengers, so he replaced every A by a D, every B
by a E, and so on through the alphabet.
Only someone who knew the ''shift by 3'' rule could decipher his
messages.
Implement the Caesar cipher
Your functions should be able to encrypt/decrypt strings with uppercase
letters, and leave any other symbol unchanged (e.g. blanks, commas,).

Cryptanalysis
9
Given ciphertext, just try all shifts of letters.
In this case you need to recognize when have plaintext.
C = GCUA VQ DTGCM
Key 1 fbtz up csfbl
Key 2 easy to break
Write a function that performs Exhaustive Search on an encrypted
message and returns a decrypted message.
Chi-square Test
10
The statistical data about English letter frequencies shows that in
a text of 1000 letters, the various English alphabets occur with

The chi-square statistic allows comparing how closely a shift of
the English frequency distribution matches the frequency
distribution of the secret message.

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
73 9 30 44 130 28 16 35 74 2 3 35 25 78 74 27 3 77 63 93 27 13 16 5 19 1
Chi-square Test
11
Here's an algorithm for computing the chi-square statistic:
1. Let ef(c) stand for the English frequency of some letter of the alphabet
2. Let mf(c) stand for the frequency of some letter of the message
3. For each possible shift s between 0 and 25:
A. For each letter c of the alphabet Compute :

B. The ChiSquare(s) value for this shift equals to the sum of all this values.

We thereby get 26 different chi-square values.
The shift s for which the number ChiSquare(s) is smallest is the most
likely candidate for the shift that was used to encipher the message
Assignment
12

Write a function that performs a frequency analysis on the
encrypted message and returns a decrypted message that
matches the frequency of the letters in English using Chi-
Square test.

1 week after the practical class.