Design and Implementation of A Product Cipher Using Substitution and Transposition Ciphers
Design and Implementation of A Product Cipher Using Substitution and Transposition Ciphers
Practical No: 1
Date of Submission:
Roll No:
Evaluation:
2 Preparedness (2)
3 Skill (4)
4 Output (2)
Lab Objective:
How different types of Substitution Ciphers and Transposition Ciphers like Hill cipher, Verman cipher,
Playfair cipher, Vigenere cipher works and their advantages and disadvantages.
Theory:
Cryptography is the practice and study of hiding information. It is the process of converting ordinary
information (plain text) into cipher text and converting cipher text again to plain text, A cipher is a pair
of algorithms which create the encryption and decryption.
Ex. If a is substituted by ‘x’ and b is substituted by ‘y’ and so on than “starbucks at three” encrypted as
PQXOYRHPXQQEOBB
1) Caesar Cipher/Additive/ Shift: It is a type of substitution cipher in which each letter in the plaintext
is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 3,
A would be replaced by D, B would become E, and so on. The method is named after Julius Caesar,
who used it to communicate with his generals.
Example
Like Plaintext: the quick brown fox jumps over the lazy dog
Cipher text: WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ
Polyalphabetic Cipher : In this cipher, we are using no. of substitutions at different positions in the
message.
1) Vigenere Cipher
2) Hill Cipher
Key: An invertible m*m matrix (where m is the block length) i.e the sender & receiver must first agree
upon a key matrix A of size m*m. A must be invertible mod 26.
Encryption: To encrypt a message using a message using the Hill Cipher we must first turn our
keyword into a key matrix (a 2*2 matrix for working with digraphs). We also turn the PT into digraphs
and each of these into a column vector. We then perform matrix multiplication modulo the length of the
alphabet (i.e 26) on each vector. These vectors are then converted back into letters to produce the
ciphertext.
Decryption:
To decrypt a ciphertext encoded using the Hill Cipher, we must find the inverse matrix. Once we have
the inverse matrix, the process is the same as encrypting. That is we multiply the inverse key matrix by
the column vectors that the ciphertext is split into, take the results modulo the length of the alphabet,
and finally convert the numbers back to letters.
2. Verman Cipher: it is a stream, polyalphabetic cipher in which the plaintext is XORed with a
random or pseudorandom stream of data to generate the ciphertext. If the stream of data is truly
random and used only once, this is the one-time pad.
Ex. H E L L O message
7 (H) 4 (E) 11 (L) 11 (L) 14 (O) message
+ 23 (X) 12 (M) 2 (C) 10 (K) 11 (L) key
= 30 16 13 21 25 message + key
E Q N V Z → ciphertext
A transposition cipher is a method of encryption by which the positions held by units of plaintext
(which are commonly characters or groups of characters) are shifted according to a regular system, so
that the ciphertext constitutes a permutation of the plaintext. That is, the order of the units is changed.
1. Rail Fence cipher: The Rail Fence cipher is a form of transposition cipher that gets its name from
the way in which it is encoded. In the rail fence cipher, the plaintext is written downwards on successive
"rails" of an imaginary fence, then moving up when we get to the bottom. The message is then read off
in rows. For example, using three "rails" and a message of 'WE ARE DISCOVERED. FLEE AT
ONCE', the cipher writes out:
Example:
W...E...C...R...L...T...E
.E.R.D.S.O.E.E.F.E.A.O.C.
..A...I...V...D...E...N..
Then reads off:
WECRL TEERD SOEEF EAOCA IVDEN
2. Single Columnar transposition: In a columnar transposition, the message is written out in rows of
a fixed length, and then read out again column by column, and the columns are chosen in some
scrambled order. Both the width of the rows and the permutation of the columns are usually defined by
a keyword. For example, the word ZEBRAS is of length 6 (so the rows are of length 6), and the
permutation is defined by the alphabetical order of the letters in the keyword. In this case, the order
would be "6 3 2 4 1 5".
In a regular columnar transposition cipher, any spare spaces are filled with nulls; in an irregular
columnar transposition cipher, the spaces are left blank. Finally, the message is read off in columns, in
the order specified by the keyword. For example, suppose we use the keyword ZEBRAS and the
message WE ARE DISCOVERED. FLEE AT ONCE. In a regular columnar transposition, we write this
into the grid as:
Example:
ZEBRAS - 632415
632415
WEAREDISCOVEREDFLEEATONCEQKJEU
As an example, we can take the result of the irregular columnar transposition in the previous section,
and perform second encryption with a different keyword, STRIPE, which gives the permutation
"564231"
Example:
564231
EVLNACDTESEAROFODEECWIREE
This is read off column-wise to give the ciphertext. CAEEN SOIAE DRLEF WEDRE EVTOC
Algorithm of Proposed Product Cipher :
Example of Product Cipher
Practical & Real-Time Application
Conclusion:
The program was tested for different sets of inputs.
Program is working SATISFACTORY NOT SATISFACTORY ( Tick
appropriate outcome)
Post Lab :
1. Explain why Modular arithmetic has been used in cryptography.
2. To break the Caesar cipher using brute force attack, how many attempts are needed?
3. Compare Substitution and Transposition techniques.