0% found this document useful (0 votes)
55 views37 pages

CNS Lab Manual

Uploaded by

Maulik Parmar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views37 pages

CNS Lab Manual

Uploaded by

Maulik Parmar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

.

CEASER CIPHER

Practical No: Date:


Aim: Understand CEASER CIPHER.

Theory:
Analyzing the Problem:
Using the Caesar Shift (3 to the right), the message

"RETURN TO ROME"

would be encrypted as,

"UHWXUA WR URPH"

In this example, 'R' is shifted to 'U', 'E' is shifted to 'H', and so on. Now, even if the enemy did
intercept the message, it would be useless, since only Caesar's generals could read it.

Thus, the Caesar cipher is a shift cipher since the ciphertext alphabet is derived from the
plaintext alphabet by shifting each letter a certain number of spaces. For example, if we use a
shift of 19, then we get the following pair of ciphertext and plaintext alphabets:

Plaintext: 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

Ciphertext: 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

To encipher a message, we perform a simple substitution by looking up each of the message's


letters in the top row and writing down the corresponding letter from the bottom row. For
example, the message

THE FAULT, DEAR BRUTUS, LIES NOT IN OUR STARS BUT IN


OURSELVES. would be enciphered as

MAX YTNEM, WXTK UKNMNL, EBXL GHM BG HNK LMTKL UNM BG


HNKLXEOXL. Essentially, each letter of the alphabet has been shifted nineteen places ahead in
the alphabet, wrapping around the end if necessary. Notice that punctuation and blanks are not
enciphered but is copied over as them.

Gandhinagar Institute Of Technology 3161606 CNS


Solution implementation is given below:-

For this solution we have to scan the following input from the user as given below.
1) Input value for Plain Text & key.
2) Encryption logic for generating Cipher Text.
3) Print function for printing Cipher Text Output.
4) Vice-versa for the Decryption logic.

Exercises:

Write a C program to implement Caesar cipher encryption-decryption.

Review Question:

1. Explain Substitution Cipher.


2. Encrypt the text ―THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG‖ with
key k=3 Using Ceaser Cipher.
3. Decrypt the text ―XLMW MW ZIVC KSSH TVIWIRXEXMSR‖with key k=4 .

Gandhinagar Institute Of Technology 3161606 CNS


.

MONOALPHABETIC CIPHER

Practical No: Date:

Aim:Introduction to MONOALPHABETIC CIPHER .

Theory:
A mono-alphabetic cipher is a simple substitution cipher wherein each letter of the plaintext is
replaced by another letter in the ciphertext. An example of a mono-alphabetic cipher key
follows:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
jrsqxzoewndyvpfatbcilhgkmu

This key means that any 'A' in the plaintext will be replaced by an 'j' in the ciphertext, any 'B'
in the plaintext will be replaced by a 'r' in the ciphertext, and so on. 3

Breaking the mono-alphabetic cipher was difficult at first, but with a little experience, it became
routine. An effective method was developed which was applied successfully to ciphertext as
short as three times the key length. The method developed follows:

1. Run the statistical analyzer on the ciphertext.

2. Using the letter frequency statistics and clever observations, make guesses at probable
letter substitutions.

3. Backtrack, if necessary.

This simple strategy overwhelms the complexity of the mono-alphabetic cipher.

Sample Example:

Here are the number of single letter occurences in the encrypted text:

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 18 3 7 35 0 2
14 14 22 26 13 0 25 39 38 12 3 7 1 14 0 21 3 19 15 41

Here is the original encrypted text:

OCDN NZHDIVM XJPMNZ RDGG NOPYT NZXPMDOT AMJH HPGODKGZ


KZMNKZXODQZNC RZ RDGG XJINDYZM NJAORVMZ DHKGZHZIOVODJIN JA
NZXPMDOT MZGVOZY KJGDXDZN DI OCZ XJIOZSO JA JKZMVODIB NTNOZHNA
IZORJMFNA VIY YVOVWVNZNC OJKDXN DIXGPYZO JKZMVODIB NTNOZH
KMJOZXODJI HZXCVIDNHNA DIOMPNDJI YZOZXODJI NTNOZHNA AJMHVG

Gandhinagar Institute Of Technology 3161606 CNS


HJYZGN JA NZXPMDOTA XMTKOJBMVKCTA YVOV WVNZ NZXPMDOTA RJMHNA
QDMPNZNA IZORJMF VIY YDNOMDWPOZY NTNOZH NZXPMDOTA VIY KJGDXDZN
JA KMDQVXT VIY XJIADYZIODVGDOTC

First we guess the word 'VIY' to be 'and'. The frequency of 'Y' is small enough to be
substituted for 'd'.

OCDN NZHDnaM XJPMNZ RDGG NOPdT NZXPMDOT AMJH HPGODKGZ


KZMNKZXODQZNC RZ RDGG XJnNDdZM NJAORaMZ DHKGZHZnOaODJnN JA
NZXPMDOT MZGaOZd KJGDXDZN Dn OCZ XJnOZSO JA JKZMaODnB NTNOZHNA
nZORJMFNA and daOaWaNZNC OJKDXN DnXGPdZO JKZMaODnB NTNOZH
KMJOZXODJn HZXCanDNHNA DnOMPNDJn dZOZXODJn NTNOZHNA AJMHaG
HJdZGN JA NZXPMDOTA XMTKOJBMaKCTA daOa WaNZ NZXPMDOTA RJMHNA
QDMPNZNA nZORJMF and dDNOMDWPOZd NTNOZH NZXPMDOTA and KJGDXDZN
JA KMDQaXT and XJnADdZnODaGDOTC

Next, the 'daOa' is assumed to be 'data'.

tCDN NZHDnaM XJPMNZ RDGG NtPdT NZXPMDtT AMJH HPGtDKGZ


KZMNKZXtDQZNC RZ RDGG XJnNDdZM NJAtRaMZ DHKGZHZntatDJnN JA
NZXPMDtT MZGatZd KJGDXDZN Dn tCZ XJntZSt JA JKZMatDnB NTNtZHNA
nZtRJMFNA and dataWaNZNC tJKDXN DnXGPdZt JKZMatDnB NTNtZH KMJtZXtDJn
HZXCanDNHNA DntMPNDJn dZtZXtDJn NTNtZHNA AJMHaG HJdZGN JA
NZXPMDtTA XMTKtJBMaKCTA data WaNZ NZXPMDtTA RJMHNA QDMPNZNA
nZtRJMF and dDNtMDWPtZd NTNtZH NZXPMDtTA and KJGDXDZN JA KMDQaXT and
XJnADdZntDaGDtTC

'Z' is guessed to be 'e', based on its frequency.

tCDN NeHDnaM XJPMNe RDGG NtPdT NeXPMDtT AMJH HPGtDKGe KeMNKeXtDQeNC


Re RDGG XJnNDdeM NJAtRaMe DHKGeHentatDJnN JA NeXPMDtT MeGated KJGDXDeN
Dn tCe XJnteSt JA JKeMatDnB NTNteHNA netRJMFNA and dataWaNeNC tJKDXN
DnXGPdet JKeMatDnB NTNteH KMJteXtDJn HeXCanDNHNA DntMPNDJn deteXtDJn
NTNteHNA AJMHaG HJdeGN JA NeXPMDtTA XMTKtJBMaKCTA data WaNe
NeXPMDtTA RJMHNA QDMPNeNA netRJMF and dDNtMDWPted NTNteH NeXPMDtTA
and KJGDXDeN JA KMDQaXT and XJnADdentDaGDtTC

'C' is guessed to be 'h', based on the 'tCe'.

thDN NeHDnaM XJPMNe RDGG NtPdT NeXPMDtT AMJH HPGtDKGe KeMNKeXtDQeNh


Re RDGG XJnNDdeM NJAtRaMe DHKGeHentatDJnN JA NeXPMDtT MeGated KJGDXDeN
Dn the XJnteSt JA JKeMatDnB NTNteHNA netRJMFNA and dataWaNeNh tJKDXN
DnXGPdet JKeMatDnB NTNteH KMJteXtDJn HeXhanDNHNA DntMPNDJn deteXtDJn

Gandhinagar Institute Of Technology 3161606 CNS


.

NTNteHNA AJMHaG HJdeGN JA NeXPMDtTA XMTKtJBMaKhTA data WaNe


NeXPMDtTA RJMHNA QDMPNeNA netRJMF and dDNtMDWPted NTNteH NeXPMDtTA
and KJGDXDeN JA KMDQaXT and XJnADdentDaGDtTh

'netRJMF' is guessed to be 'network'.

thDN NeHDnar XoPrNe wDGG NtPdT NeXPrDtT AroH HPGtDKGe KerNKeXtDQeNh we


wDGG XonNDder NoAtware DHKGeHentatDonN oA NeXPrDtT reGated KoGDXDeN Dn
the XonteSt oA oKeratDnB NTNteHNA networkNA and dataWaNeNh toKDXN DnXGPdet
oKeratDnB NTNteH KroteXtDon HeXhanDNHNA DntrPNDon deteXtDon NTNteHNA
AorHaG HodeGN oA NeXPrDtTA XrTKtoBraKhTA data WaNe NeXPrDtTA worHNA
QDrPNeNA network and dDNtrDWPted NTNteH NeXPrDtTA and KoGDXDeN oA
KrDQaXT and XonADdentDaGDtTh

'reGated' is guessed to be 'related'.

thDN NeHDnar XoPrNe wDll NtPdT NeXPrDtT AroH HPltDKle KerNKeXtDQeNh we wDll
XonNDder NoAtware DHKleHentatDonN oA NeXPrDtT related KolDXDeN Dn the XonteSt
oA oKeratDnB NTNteHNA networkNA and dataWaNeNh toKDXN DnXlPdet oKeratDnB
NTNteH KroteXtDon HeXhanDNHNA DntrPNDon deteXtDon NTNteHNA AorHal HodelN oA
NeXPrDtTA XrTKtoBraKhTA data WaNe NeXPrDtTA worHNA QDrPNeNA network and
dDNtrDWPted NTNteH NeXPrDtTA and KolDXDeN oA KrDQaXT and XonADdentDalDtTh

'D' is guessed to be 'i', based on 'wDll' and 'Dn'.

thiN NeHinar XoPrNe will NtPdT NeXPritT AroH HPltiKle KerNKeXtiQeNh we will
XonNider NoAtware iHKleHentationN oA NeXPritT related KoliXieN in the XonteSt oA
oKeratinB NTNteHNA networkNA and dataWaNeNh toKiXN inXlPdet oKeratinB NTNteH
KroteXtion HeXhaniNHNA intrPNion deteXtion NTNteHNA AorHal HodelN oA
NeXPritTA XrTKtoBraKhTA data WaNe NeXPritTA worHNA QirPNeNA network and
diNtriWPted NTNteH NeXPritTA and KoliXieN oA KriQaXT and XonAidentialitTh

'NeHinar' is guessed to be 'seminar'.

this seminar XoPrse will stPdT seXPritT Arom mPltiKle KersKeXtiQesh we will Xonsider
soAtware imKlementations oA seXPritT related KoliXies in the XonteSt oA oKeratinB
sTstemsA networksA and dataWasesh toKiXs inXlPdet oKeratinB sTstem KroteXtion
meXhanismsA intrPsion deteXtion sTstemsA Aormal models oA seXPritTA XrTKtoBraKhTA
data Wase seXPritTA wormsA QirPsesA network and distriWPted sTstem seXPritTA and
KoliXies oA KriQaXT and XonAidentialitTh

'XoPrse' is guessed to be 'course'. 'stPdT' is guessed to be 'study'. 'seXPritT' is guessed to be


'security'.

Gandhinagar Institute Of Technology 3161606 CNS


this seminar course will study security from multiKle KersKectiQesh we will consider software
imKlementations of security related Kolicies in the conteSt of oKeratinB systemsf networksf
and dataWasesh toKics includet oKeratinB system Krotection mechanismsf intrusion detection
systemsf formal models of securityf cryKtoBraKhyf data Wase securityf wormsf Qirusesf
network and distriWuted system securityf and Kolicies of KriQacy and confidentialityh

The final letters are filled in by scanning the text.

this seminar course will study security from multiple perspectivesh we will consider software
implementations of security related policies in the context of operating systemsf networksf
and databasesh topics includet operating system protection mechanismsf intrusion detection
systemsf formal models of securityf cryptographyf data base securityf wormsf virusesf
network and distributed system securityf and policies of privacy and confidentialityh

Some of the punctuation in the original message seems to have translated to alphabetic
characters. The original mono-alphabetic cipher implementation (which eventually turns
out to be a shift cipher) comes under scrutiny.
When we write out the key(EX.2)
ABCDEFGHIJKLMNOPQRSTUVWXYZ
fghijk lmnopqrstuvwxyzabcde

Exercises:

Write a C program to implement Monoalphabetic cipher encryption-decryption.

Review Question:

1. Explain Monoalphabetic vs Polyalphabetic


2. Encrypt the paragraph using above mentioned key.
―Monoalphabetic cipher is a substitution cipher in which for a given key the cipher
alphabet for each plain alphabet is fixed throughout the encryption process. For example
if A is encrypted as D for any number of occurrence in that plaintext A will always get
encrypted to D.‖

Gandhinagar Institute Of Technology 3161606 CNS


.

PLAYFAIR CIPHER
Practical No: Date:
Aim:Introduction to PLAYFAIR CIPHER.

Theory:
Analyzing the Problem:
By analyzing the problem I found required two basic steps for implementing the
data encryption using Play Fair cipher
1) Generate Key matrix

2) Encrypt the data using encryption rule and key matrix

1) Generating Key matrix

To Generate the key matrix take any random key of any length and form a 5X5
matrix. Go on filling the raws of the matrix with the key characters ( if repeating
character occurs then ignore it). Fill the remaining matrix with alphabets from A to
Z (except those already occurred in the key).

For example for the key "monarchy" we have the matrix as follow

M O N A R

C H Y B D

E F G I/J K

L P Q S T

U V W X Z

2) Encrypt the data using encryption rule and key matrix


To Encrypt the data take two characters at time from plain text file and encrypt it
using one of the following rules.

Encryption rules

i) Repeating plain text letters that would fall in the same pair are separated
with filler letter, such as x.( i.e. Balloon becomes Ba, lx, lo, on)

ii) If both the characters are in the same raw then replace each with the character
to its right, with the last character followed by the first, in the matrix.

Gandhinagar Institute Of Technology 3161606 CNS


iii) If both the characters are in the same column then replace each with the
character below it, with the bottom character followed by the top, in the matrix.
iv) Otherwise each plain text letter is replaced by the letter that lies in its own row
and the column occupied by the other plain text letter

Example:
Using key as "monarchy" we have
- Encryption of AR as RM
- Encryption of MU as CM
- Encryption of BP as IM

Designing the Solution:

For the solution we have to implement the following functions given below. 1)
Input function for key & Plain Text.
2) Matrix generation.
3) Encryption function for generating Cipher Text.
4) Print function for printing Cipher Text Output.

Compilation /Running and Debugging the Solution


- Open the file Playfair.cpp.
- Compile using Alt+F9
- Run using Ctl+F9
- View output using Alt+F5

Testing the SolutionBy Testing the program we get the cipher text as output.

Exercises:

Write a C program to implement Playfair cipher encryption-decryption.

Review Question:

1. Using the key =‖monarchy‖ create the key square ,encrypt the below text
(a) ―we are discovered save yourself‖
(b) ―It was used for tactical purposes by British‖
(c) ―The technique encrypts pairs of letters called digraphs ‖
(d) ―The Playfair is significantly harder to break‖

Gandhinagar Institute Of Technology 3161606 CNS


.

POLYALPHABETIC

Practical No: Date:

Aim:Introduction to POLYALPHABETIC

Theory:
The Alberti cipher by Leon Battista Alberti around 1467 was believed to be the first
polyalphabetic cipher. Alberti used a mixed alphabet to encrypt a message, but whenever he
wanted to, he would switch to a different alphabet, indicating that he had done so by including
an uppercase letter or a number in the cryptogram. For this encipherment Alberti used a decoder
device, his cipher disk, which implemented a polyalphabetic substitution with mixed alphabets.

Although Alberti is usually considered the father of polyalphabetic cipher, it has been claimed
that polyalphabetic ciphers may have been developed by the Arab cryptologist Al Kindi 600
years before Alberti. Johannes Trithemius—in his book Polygraphiae libri sex (Six books of
polygraphia), which was published in 1518 after his death—invented aprogressive key
polyalphabetic cipher called the Trithemius cipher. Unlike Alberti's cipher, which switched
alphabets at random intervals, Trithemius switched alphabets for each letter of the message. He
started with a tabula recta, a square with 26 alphabets in it (although Trithemius, writing in
Latin, used 24 alphabets). Each alphabet was shifted one letter to the left from the one above it,
and started again with A after reaching Z (see image).

Table of PolyAlphabetic

Gandhinagar Institute Of Technology 3161606 CNS


Trithemius's idea was to encipher the first letter of the message using the first shifted alphabet, so A
became B, B became C, etc. The second letter of the message was enciphered using the second
shifted alphabet, etc. Alberti's cipher disk implemented the same scheme. It had two alphabets,
one on a fixed outer ring, and the other on the rotating disk. A letter is enciphered by looking for
that letter on the outer ring, and encoding it as the letter underneath it on the disk. The disk started
with A underneath B, and the user rotated the disk by one letter after encrypting each letter.

The cipher was trivial to break, and Alberti's machine implementation not much more difficult.
Keyprogression in both cases was poorly concealed from attackers. Even Alberti's
implementation of hispolyalphabetic cipher was rather easy to break (the capitalized letter is a
major clue to the cryptanalyst). For most of the next several hundred years, the significance of
using multiple substitution alphabets was missed by almost everyone. Polyalphabetic substitution
cipher designers seem to have concentrated on obscuring the choice of a few such alphabets
(repeating as needed), not on the increased security possible by using many and never repeating
any.

The principle (particularly Alberti's unlimited additional substitution alphabets) was a major
advance—the most significant in the several hundred years since frequency analysis had been
developed. A reasonable implementation would have been (and, when finally achieved, was)
vastly harder to break. It was not until the mid-19th century (in Babbage's secret work during
the Crimean War and Friedrich Kasiski's generally equivalent public disclosure some years
later), thatcryptanalysis of well-implemented polyalphabetic ciphers got anywhere at all.

Exercises:

Write a C program to implement Polyalphabetic cipher encryption-decryption.

Review Question:
1. Encrypt the following text using Polyalphabetic Cipher.
(a) ―Must see you over Cadogan West Coming at once‖
(b) ―involve something more than just sliding one alphabet against another‖
(c) ―the wheel is constructed from four disks‖
(d) ―the war will be over within two weeks‖

Gandhinagar Institute Of Technology 3161606 CNS


.

HILL CIPHER

Practical No: Date:


Aim:Introduction to HILL CIPHER.

Theory:
Analyzing the Problem:

Each letter is represented by a number modulo 26.(Often the simple scheme A = 0,B=1,.., Z = 25
is used, but this is not an essential feature of the cipher.) To encrypt a message, each block of n
letters (considered as an n-component vector) is multiplied by an invertible n × n matrix, again
modulus 26. To decrypt the message, each block is multiplied by the inverse of the matrix used
for encryption.

The matrix used for encryption is the cipher key, and it should be chosen randomly from the set
of invertible n × n matrices (modulo 26). The cipher can, of course, be adapted to an alphabet
with any number of letters; all arithmetic just needs to be done modulo the number of letters
instead of modulo 26.

Sample Example:

Let

be the key and suppose the plaintext message is HELP. Then this plaintext is represented by two
pairs

Then we compute

and continue encryption as follows:

Gandhinagar Institute Of Technology 3161606 CNS


The matrix K is invertible, hence exists such that .
To implement decrypting, we compute

Then we compute

Therefore

Exercises:

Write a C program to implement Hill cipher encryption-decryption.

Review Question:
1. Encrypt the message ―meet me at the usual place at ten rather than eight oclock‖
9 4
using the Hill cipher with the key .Show your calculations and the result.
5 7
2. Show the calculation for the corresponding decryption of the cipher text to recover the
original text.

Gandhinagar Institute Of Technology 3161606 CNS


.

DES Algorithm

Practical No: Date:

Aim:Introduction to simple DES algorithm

Theory:
Over the last decade, there has been an accelerating increase in the accumulations and
communication of digital data by government, industry and by other organizations in the private
sector. The contents of these communicated and stored data often have very significant value
and/or sensitivity. It is now common to find data transmissions which constitute funds transfers
of several million dollars, purchase or sale of securities, warrants for arrests or arrest and
conviction records being communicated between law enforcement agencies, airline reservations
and ticketing representing investment and value both to the airline and passengers, and health
and patient care records transmitted among physicians and treatment centers.

The increasing volume, value and confidentiality of these records regularly transmitted and
stored by commercial and government agencies has led to heightened recognition and concern
over their exposures to unauthorized access and use. This misuse can be in the form of theft or
defalcations of data records representing money, malicious modification of business inventories
or the interception and misuse of confidential information about people. The need for protection
is then apparent and urgent.

It is recognized that encryption (otherwise known as scrambling, enciphering or privacy


transformation) represents the only means of protecting such data during transmission and a
useful means of protecting the content of data stored on various media, providing encryption of
adequate strength can be devised and validated and is inherently integrable into system
architecture. The National Bureau of Standards solicits proposed techniques and algorithms for
computer data encryption. The Bureau also solicits recommended techniques for implementing
the cryptographic function: for generating, evaluating, and protecting cryptographic keys; for
maintaining files encoded under expiring keys; for making partial updates to encrypted files; and
mixed clear and encrypted data to permit labelling, polling, routing, etc. The Bureau in its role
for establishing standards and aiding government and industry in assessing technology, will
arrange for the evaluation of protection methods in order to prepare guidelines.

The origins of DES go back to the early 1970s. In 1972, after concluding a study on the US
government's computer security needs, the US standards body NBS (National Bureau of
Standards) — now named NIST (National Institute of Standards and Technology) — identified a
[1]
need for a government-wide standard for encrypting unclassified, sensitive information.
Accordingly, on 15 May 1973, after consulting with the NSA, NBS solicited proposals for a
cipher that would meet rigorous design criteria. None of the submissions, however, turned out to
be suitable. A second request was issued on 27 August 1974. This time, IBM submitted a
candidate which was deemed acceptable — a cipher developed during the period 1973 –1974

Gandhinagar Institute Of Technology 3161606 CNS


based on an earlier algorithm, Horst Feistel's Lucifer cipher. The team at IBM involved in cipher
design and analysis included Feistel, Walter Tuchman, Don Coppersmith, Alan Konheim, Carl
Meyer, Mike Matyas, Roy Adler, Edna Grossman, Bill Notz, Lynn Smith, and Bryant
Tuckerman.

The DES (Data Encryption Standard) algorithm is the most widely used encryption algorithm in
the world. For many years, and among many people, "secret code making" and DES have been
synonymous. And despite the recent coup by the Electronic Frontier Foundation in creating a
$220,000 machine to crack DES -encrypted messages, DES will live on in government and
banking for years to come through a life- extending version called "triple-DES."

Gandhinagar Institute Of Technology 3161606 CNS


.

1 Process the key

1.1 Get a 64-bit key from the user. (Every 8th bit (the leastsignificant bit of each byte) is
considered a parity bit. For a key tohave correct parity, each byte should contain an odd number
of "1"bits.) This key can be entered directly, or it can be the result ofhashing something else.
There is no standard hashing algorithm for thispurpose.

1.2 Calculate the key schedule.

1.2.1 Perform the following permutation on the 64-bit key. (Theparity bits are discarded,
reducing the key to 56 bits. Bit 1 (the mostsignificant bit) of the permuted block is bit 57 of the
original key,bit 2 is bit 49, and so on with bit 56 being bit 4 of the original key.)

Permuted Choice 1 (PC-1)

57 49 41 33 25 17 9
1 58 50 42 34 26 18
10 2 59 51 43 35 27
19 11 3 60 52 44 36
63 55 47 39 31 23 15
7 62 54 46 38 30 22
14 6 61 53 45 37 29
21 13 5 28 20 12 4

1.2.2 Split the permuted key into two halves. The first 28 bits are called C[0] and the last 28 bits
are called D[0].

1.2.3 Calculate the 16 subkeys. Start with i = 1.

1.2.3.1 Perform one or two circular left shifts on both C[i-1] andD[i-1] to get C[i] and D[i],
respectively. The number of shifts periteration are given in the table below.

Iteration # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Left
Shifts 1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1

1.2.3.2 Permute the concatenation C[i]D[i] as indicated below. Thiswill yield K[i], which is 48
bits long.

Permuted Choice 2 (PC-2)

14 17 11 24 1 5
3 28 15 6 21 10

Gandhinagar Institute Of Technology 3161606 CNS


23 19 12 4 26 8
16 7 27 20 13 2
41 52 31 37 47 55
30 40 51 45 33 48
44 49 39 56 34 53
46 42 50 36 29 32

1.2.3.3 Loop back to 1.2.3.1 until K[16] has been calculated.


2 Process a 64-bit data block.

2.1 Get a 64-bit data block. If the block is shorter than 64 bits, itshould be padded as appropriate
for the application.

2.2 Perform the following permutation on the data block.

Initial Permutation (IP)

58 50 42 34 26 18 10 2
60 52 44 36 28 20 12 4
62 54 46 38 30 22 14 6
64 56 48 40 32 24 16 8

57 49 41 33 25 17 9 1
59 51 43 35 27 19 11 3
61 53 45 37 29 21 13 5
63 55 47 39 31 23 15 7

2.3 Split the block into two halves. The first 32 bits are calledL[0], and the last 32 bits are called
R[0].

2.4 Apply the 16 subkeys to the data block. Start with i = 1.

2.4.1 Expand the 32-bit R[i-1] into 48 bits according to the bit-selection function below.

Expansion (E)

32 1 2 3 4 5
456789
8 9 10 11 12 13
12 13 14 15 16 17
16 17 18 19 20 21
20 21 22 23 24 25
24 25 26 27 28 29
28 29 30 31 32 1
Gandhinagar Institute Of Technology 3161606 CNS
.

2.4.2 Exclusive-or E(R[i-1]) with K[i].

2.4.3 Break E(R[i-1]) xor K[i] into eight 6-bit blocks. Bits 1-6 areB[1], bits 7-12 are B[2], and so
on with bits 43-48 being B[8].

2.4.4 Substitute the values found in the S-boxes for all B[j]. Start with j = 1. All values in the S-
boxes should be considered 4 bits wide.

2.4.4.1 Take the 1st and 6th bits of B[j] together as a 2-bit value (call it m) indicating the row in
S[j] to look in for the substitution
2.4.4.2 Take the 2nd through 5th bits of B[j] together as a 4-bit value (call it n) indicating the
column in S[j] to find the substitution.

2.4.4.3 Replace B[j] with S[j][m][n].

Substitution Box 1

(S[1])

14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7
0 15 7 4 14 2 13 1 10 6 12 11 9 5 3 8
4 1 14 8 13 6 2 11 15 12 9 7 3 10 5 0
15 12 8 2 4 9 1 7 5 11 3 14 10 0 6 13

S[2]

15 1 8 14 6 11 3 4 9 7 2 13 12 0 5 10
3 13 4 7 15 2 8 14 12 0 1 10 6 9 11 5
0 14 7 11 10 4 13 1 5 8 12 6 9 3 2 15
13 8 10 1 3 15 4 2 11 6 7 12 0 5 14 9

S[3]

10 0 9 14 63 15 5 1 13 12 7 11 4 2 8
13 7 0 9 3 4 6 10 2 8 5 14 12 11 15 1
13 6 4 9 8 15 3 0 11 1 2 12 5 10 14 7
1 10 13 0 6 9 8 7 4 1514 3 11 5 2 12

S[4]

7 13 14 3 0 6 9 10 1 2 8 5 11 12 4 15
13 8 11 5 615 0 3 4 7 2 12 1 10 14 9
10 6 9 0 1211 7 13 15 1 3 14 5 2 8 4
3 15 0 6 10 1 13 8 9 4 5 11 12 7 2 14

Gandhinagar Institute Of Technology 3161606 CNS


S[5]

2 12 41 7 10 11 6 8 5 3 15 13 0 14 9
14 11 2 12 4 7 13 1 5 0 15 10 3 9 8 6
4 2 1 11 10 13 7 8 15 9 12 5 6 3 0 14
11 8 12 7 1 14 2 13 6 15 0 9 10 4 5 3

S[6]

12 1 10 15 9 2 6 8 0 13 3 4 14 7 5 11
10 15 4 2 7 12 9 5 6 1 13 14 0 11 3 8
9 14 15 5 2 8 12 3 7 0 4 10 1 13 11 6
4 3 2 12 9 5 15 10 11 14 1 7 6 0 8 13

S[7]

4 11 2 14 15 0 8 13 3 12 9 7 5 10 6 1
13 0 11 7 4 9 1 10 14 3 5 12 2 15 8 6
1 4 11 13 12 3 7 14 10 15 6 8 0 5 9 2
6 11 13 8 1 4 10 7 9 50 15 14 2 3 12

S[8]

13 2 8 4 6 15 11 1 10 9 3 14 5 0 12 7
1 15 13 8 10 3 7 4 12 5 6 11 0 14 9 2
7 11 4 1 9 12 14 2 0 6 10 13 15 3 5 8
2 1 14 7 4 10 8 13 15 12 9 0 3 5 6 11

2.4.4.4 Loop back to 2.4.4.1 until all 8 blocks have been replaced.

2.4.5 Permute the concatenation of B[1] through B[8] as indicated below.

Permutation P

16 7 20 21
29 12 28 17
1 15 23 26
5 18 31 10
2 8 24 14
32 27 3 9
19 13 30 6
22 11 4 25

Gandhinagar Institute Of Technology 3161606 CNS


.

2.4.6 Exclusive-or the resulting value with L[i-1]. Thus, all together,your R[i] = L[i-1] xor
P(S[1](B[1])...S[8](B[8])), where B[j] is a 6-bit block of E(R[i-1]) xor K[i]. (The function for
R[i] is more concisely written as, R[i] = L[i-1] xor f(R[i-1], K[i]).)

2.4.7 L[i] = R[i-1].

2.4.8 Loop back to 2.4.1 until K[16] has been applied.

2.5 Perform the following permutation on the block R[16]L[16]. (Note that block R precedes
block L this time.)

-1
Final Permutation (IP )

40 8 48 16 56 24 64 32
39 7 47 15 55 23 63 31
38 6 46 14 54 22 62 30
37 5 45 13 53 21 61 29
36 4 44 12 52 20 60 28
35 3 43 11 51 19 59 27
34 2 42 10 50 18 58 26
33 1 41 9 49 17 57 25

This has been a description of how to use the DES algorithm to encrypt one 64-bit block. To
decrypt, use the same process, but just use the keys K[i] in reverse order. That is, instead of
applying K[1] for the first iteration, apply K[16], and then K[15] for the second, on down to
K[1].
Exercises:

Write a C program to implement simple DES

Review Question:
1. Why is it important to study the Feistel cipher?
2. What is the difference between diffusion and confusion?
3. Explain the avalanche effect.

Gandhinagar Institute Of Technology 3161606 CNS


Gandhinagar Institute Of Technology 3161606 CNS
.

Diffie-Hellman Key Exchange

Practical No: Date:

Aim:Introduction to Diffie-Hellman Key Exchange.

Theory:
Analyzing the Problem:
Diffie Hellman key exchange algorithm uses asymmetric key principles for the distribution
of symmetric keys to both parties in a communication network. Diffie Hellman utilizes the
public& private key of asymmetric key cryptography to exchange the secret key.
Before going in depth of Diffie Hellman Algorithm, we define primitive root of a prime
number 'p' as one whose powers generate all the integers from 1 to p-1, i.e. if 'a' is the
primitive root of a prime no 'p', then,
2 3 p-1
a mod p , a mod p , a mod p, .............. a mod p generate all distinct integers from 1 to
(p-1) in some permutation.

 The steps for Diffie Hellman key exchange algorithm are:

Step 1 : GLOBAL PUBLIC ELEMENTS


Select any prime no : 'q'
Calculate the primitive root of q : 'a' such that a<q

Step 2 : ASYMMETRIC KEY GENERATION BY USER


'A'Select a random number as the private key XA where XA<
X
q Calculate the public key YA where YA = a A mod q

Step 3 : KEY GENERATION BY USER 'B'


Select a random number as the private key XB where XB< q
X
Calculate the public key YB where YB = a B mod q

Step 4 : Exchange the values of public key between A & B

Step 5 : SYMMETRIC KEY (K) GENERATION BY USER


X
'A'K= YB A mod q

Step 6 : SYMMETRIC KEY (K) GENERATION BY USER


X
'B'K= YA B mod q
It can be easily be proved that the key K generated by this algorithm by both
parties are the same.

Gandhinagar Institute Of Technology 3161606 CNS


Sample Example:

 Suppose Alice and Bob agree to use p = 47 and g = 5.

 Alice chooses a number between 0 and 46, say a = 18.

 Bob chooses a number between 0 and 46, say b = 22.

 Alice publishes ga (mod p), i.e.

u = 518 (mod 47) = 2.

 Bob publishes gb (mod p), i.e.

v = 522 (mod 47) = 28.

 If Alice wants to know the secret key k, she takes Bob’s public number, v = 28,
and raises it to her private number, a = 18 (taking the result mod 47).

This gives her: 2818 (mod 47) = 24.

 If Bob wants to know the secret key, he takes Alice’s public number, u = 2,
and raises it to his private number, b = 22 (taking the result mod 47).

This gives him: 222 (mod 47) = 24.

Exercises:

Write a C program to implement Diffie-Hellmen Key exchange Method.

Review question:
1. Users A and B use the Diffie-Hellman key exchange technique with a common prime
q = 71 and a primitive root α = 7.
a. If user A has private key XA = 5, what is A’s public key YA?
b. If user B has private key XB = 12, what is B’s public key YB?
c. What is the shared secret key?
2 . Consider a Diffie-Hellman scheme with a common prime q = 11 and a primitive root
α = 2.
a. Show that 2 is a primitive root of 11.
b. If user A has public key YA = 9, what is A’s private key XA?
c. If user B has public key YB = 3, what is the secret key K shared with A?

Gandhinagar Institute Of Technology 3161606 CNS


.

RSA

Practical No: Date:


Aim:Introduction to RSA encryption decryption algorithm

Theory:
Analyzing the Problem:

Key Generation Algorithm:

1. Choose two very large random prime


integers: p and q.
2. Compute n and φ(n):
n = pq and φ(n) = (p-1)(q-1)
3. Choose an integer e, 1 < e < φ(n) such that:
gcd(e, φ(n)) = 1(where gcd means greatest common denominator)
4. Compute d, 1 < d < φ(n) such that:
ed ≡ 1 (mod φ(n))

 the public key is (n, e) and the private key is (n, d)
 the values of p, q and φ(n) are private
 e is the public or encryption exponent
 d is the private or decryption exponent

Encryption
e
The cyphertext C is found by the equation 'C = M mod n' where M is the original message.

Decryption
d
The message M can be found form the cyphertext C by the equation 'M = C mod n'.

Sample Example:

1. Select the prime integers q=11, q=3.


2. n=pq=33; φ(n)=(p-1)(q-1)=20
3. Choose e=3
o Check gcd(3,20)=1
4. Compute d=7
o (3)d ≡ 1 (mod 20)

Therefore the public key is (n, e) = (33, 3) and the private key is (n, d) = (33, 7).

Now say we wanted to encrypt the message M=7


e
 C = M mod n
3
 C = 7 mod 33
 C = 343 mod 33
Gandhinagar Institute Of Technology 3161606 CNS
 C = 13

So now the cyphertext C has been found. The decryption of C is performed as follows.
d
 M' = C mod n
7
 M' = 13 mod 33
 M' = 62,748,517 mod 33
 M' = 7

Exercises:

Write a C program to implement RSA encryption-decryption algorithm

Review Question:
1. What are the principal elements of a public-key cryptosystem?
2. What requirements must a public-key cryptosystems fulfill to be a secure algorithm?
3. In a public-key system using RSA, you intercept the ciphertext C = 10 sent to a user
whose public key is e = 5, n = 35. What is the plaintextM?
4. Perform encryption and decryption using the RSA algorithm, for the
following:
a. p = 3; q = 11, e = 7; M = 5
b. p = 5; q = 11, e = 3; M = 9
c. p = 7; q = 11, e = 17; M = 8
d. p = 11; q = 13, e = 11; M = 7
e. p = 17; q = 31, e = 7; M = 2
Hint: Decryption is not as hard as you think; use some finesse.

Gandhinagar Institute Of Technology 3161606 CNS


.

Digital signature algorithm

Practical No: Date:

Aim:Introduction to digital signature algorithm.

Theory:
A digital signature is a mathematical scheme for demonstrating the authenticity of a digital
message or documents. A valid digital signature gives a recipient reason to believe that the
message was created by a known sender, that the sender cannot deny having sent the message
(authentication and non-repudiation), and that the message was not altered in transit (integrity).

A digital signature scheme typically consists of three algorithms;

 A key generation algorithm that selects a private keyuniformly at random from a set of
possible private keys. The algorithm outputs the private key and a corresponding public key.
 A signing algorithm that, given a message and a private key, produces a signature.

 A signature verifying algorithm that, given the message, public key and signature, either
accepts or rejects the message's claim to authenticity.

Two main properties are required. First, the authenticity of a signature generated from a fixed
message and fixed private key can be verified by using the corresponding public key. Secondly,
it should be computationally infeasible to generate a valid signature for a party without knowing
that party's private key. A digital signature is an authentication mechanism that enables the
creator of the message to attach a code that acts as a signature.

Formally, a digital signature scheme is a triple of probabilistic polynomial time algorithms, (G,
S, V), satisfying:
 G (key-generator) generates a public key, pk, and a corresponding private key, sk, on
n
input 1 ,whe re n is the security parameter.

 S (signing) returns a tag, t, on the inputs: the private key, sk, and a string, x.

 V (verifying) outputs accepted or rejected on the inputs: the public key, pk, a string, x,
and atag, t.

For correctness, S and V must satisfy

n
Pr [ (pk, sk) ← G(1 ), V( pk, x, S(sk, x) ) = accepted ] = 1.

Gandhinagar Institute Of Technology 3161606 CNS


A digital signature scheme is secure if for every non-uniform probabilistic polynomial time
adversary, A
Pr [ (pk, sk) ← G(1n), (x, t) ← AS(sk, · )(pk, 1n), x∉ Q, V(pk, x, t) = accepted] < negl(n),

S(sk, · )
where A denotes that A has access to the oracle, S(sk, · ), and Q denotes the set of the
queries on S made by A, which knows the public key, pk, and the security parameter, n. Note
that we require any adversary cannot directly query the string, x, on S.

Exercises:
Write a C program to implement digital signature algorithm.

Review Question:
1. What are the properties a digital signature should have?
2. What requirements should a digital signature scheme satisfy?
3. What is the difference between direct and arbitrated digital signature?
4. In what order should the signature function and the confidentiality function be applied
to a message, and why?

Gandhinagar Institute Of Technology 3161606 CNS


.

CRYPTOOL

Practical No: Date:

Aim:Introduction to cryptool.

Theory:
CrypTool is an open source e-learning tool illustrating cryptographic and cryptanalytic concepts.
CrypTool implements more than 300 algorithms. Users can adjust these with own parameters.
The graphical interface, online documentation, analytic tools and algorithms of CrypTool
introduce users to the field of cryptography. Classical ciphersare available alongside asymmetric
cryptography including RSA, elliptic curve cryptography, digital signatures, homomorphic
encryption, and Diffie–Hellman key exchange, many of which are visualized by animations.

CrypTool software package contents

 CrypTool program
 AES Tool
 Extensive online help
 Script(PDF) with background information on

Encryption algorithm,prime numbers, digital signature, elliptic curves, public key
certification.

Various uses of CrypTool are as below:

Hybrid Encryption

1. Hybrid encryption visualized: Preparation

Gandhinagar Institute Of Technology 3161606 CNS


2. Hybrid encryption visualized: Cryptography

3. Hybrid encryption visualized: Result

Gandhinagar Institute Of Technology 3161606 CNS


.

Digital Signature
 Digital Signature Visualized: Preparation

 Digital Signature Visualized: Cryptography

Gandhinagar Institute Of Technology 3161606 CNS


 Digital Signature Visualized: Result

Short RSA Module

 Enter public RSA parameters

Gandhinagar Institute Of Technology 3161606 CNS


.

 Factorize RSA modulus

 Determine private key d

Gandhinagar Institute Of Technology 3161606 CNS


 Adjust options

 Decrypt cipher text

Gandhinagar Institute Of Technology 3161606 CNS


.

Exercises:
Perform any one of the above encryption technique with cryptool.

Review Question:
1. Install JCrypTool
2. Analyze any one algorithm using JCrypTool

Gandhinagar Institute Of Technology 3161606 CNS


Gandhinagar Institute Of Technology 3161606 CNS
.

Wireshark

Practical No: Date:

Aim:Study and use the Wireshark for the various network protocols.

Theory:
What is Wireshark?
Wireshark is a network packet analyzer. A network packet analyzer will try to capture network
packets and tries to display that packet data as detailed as possible. A network packet analyzer as
a measuring device used to examine what’s going on inside a network cable, just like a
voltmeter is used by an electrician to examine what’s going on inside an electric cable (but at a
higher level, of course). In the past, such tools were either very expensive, proprietary, or both.
However, with the advent of Wireshark, all that has changed. Wireshark is perhaps one of the
best open source packet analyzers available today.

Features:

The following are some of the many features Wireshark provides:


• Available for UNIX and Windows.
• Capture live packet data from a network interface.
• Open files containing packet data captured with tcpdump/WinDump, Wireshark, and a
numberof other packet capture programs.
• Import packets from text files containing hex dumps of packet data.
• Display packets with very detailed protocol information.
• Save packet data captured.
• Export some or all packets in a number of capture file formats.
• Filter packets on many criteria.
• Search for packets on many criteria.
• Colorize packet display based on filters.
• Create various statistics.
Your Wireshark window should look similar to the window shown in Figure 1. If you are unable
to run Wireshark on a live network connection, you can download a packet trace that was created
when the steps above were followed.

Gandhinagar Institute Of Technology 3161606 CNS


The example in Figure shows in the packet-listing window that two HTTP messages were
captured: the GET message (from your browser to the gaia.cs.umass.edu web server) and the
response message from the server to your browser. The packet-contents window shows details of
the selected message (in this case the HTTP OK message, which is highlighted in the packet
listing window). Recall that since the HTTP message was carried inside a TCP segment, which
was carried inside an IP datagram, which was carried within an Ethernet frame, Wireshark
displays the Frame, Ethernet, IP, and TCP packet information as well. We want to minimize the
amount of non-HTTP data displayed so make sure the boxes at the far left of the Frame,
Ethernet, IP and TCP information have a plus sign or a right-pointing triangle (which means
there is hidden, undisplayed information), and the HTTP line has a minus sign or a down-
pointing triangle (which means that all information about the HTTP message is displayed).

Exercises:

Perform Below Exercises using Wireshark


1. Is your browser running HTTP version 1.0 or 1.1? What version of HTTP is the server
running?
2. What languages (if any) does your browser indicate that it can accept to the server?
3. What is the IP address of your computer? Of the gaia.cs.umass.edu server?
4. What is the status code returned from the server to your browser?
5. When was the HTML file that you are retrieving last modified at the server?
6. How many bytes of content are being returned to your browser?
7. By inspecting the raw data in the packet content window, do you see any headers within the
data that are not displayed in the packet-listing window? If so, name one.

Gandhinagar Institute Of Technology 3161606 CNS


.

8. Inspect the contents of the first HTTP GET request from your browser to the server. Do
you see an ―IF-MODIFIED-SINCE‖ line in the HTTP GET?
9. Inspect the contents of the server response. Did the server explicitly return the contents of
the file? How can you tell?
10. Now inspect the contents of the second HTTP GET request from your browser to the server.
Do you see an ―IF-MODIFIED-SINCE:‖ line in the HTTP GET? If so, what information
follows the ―IF-MODIFIED-SINCE:‖ header?
What is the HTTP status code and phrase returned from the server in response to this second
HTTP GET? Did the server explicitly return the contents of the file? Explain.

Gandhinagar Institute Of Technology 3161606 CNS

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy