0% found this document useful (0 votes)
261 views

IS Lab Mannual

The document describes the Data Encryption Standard (DES) algorithm for encryption and decryption. It explains the key components of DES including initial and final permutation of blocks, breaking blocks into left and right parts, performing permutations and substitutions over 16 rounds using a 48-bit round key, and rejoining the left and right parts. An example is provided to illustrate the general structure and process of DES including the round function, key schedule, and additional initial and final permutations.

Uploaded by

vasudha sankpal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
261 views

IS Lab Mannual

The document describes the Data Encryption Standard (DES) algorithm for encryption and decryption. It explains the key components of DES including initial and final permutation of blocks, breaking blocks into left and right parts, performing permutations and substitutions over 16 rounds using a 48-bit round key, and rejoining the left and right parts. An example is provided to illustrate the general structure and process of DES including the round function, key schedule, and additional initial and final permutations.

Uploaded by

vasudha sankpal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

lO MoARcPSD|19 924 880

lOMoARcPSD|199 248 80

EX.NO:1
DISPLAY THE RESULT

AIM:

Write a Java/C/C++/Python program that contains a string (char pointer) with a value \Hello
World9. The program should AND OR and XOR each character in this string with 127 and
display the result

DESCRIPTION:

(a) String

The string is the one-dimentional array of characters terminated by null(‘\0’). Each and every
character in the array consumes one byte of memory, and the last character must always be 0. The
termination character(‘\0’) is used to identify where the string ends. In C language string declaration
can be done in two ways.
1. By char array
2. By string literal

EXAMPLE:
Let’s see the example of declaring string by char array in C language.

Char ch[17]={‘o’,’n’,’l’,’i’,’n’,’e’,’s’,’m’,’a’,’r’,’t’,’t’,’r’,’a’,’i’,’n’,’e’,’r’,’\0’};

As we know, array index starts from 0, so it will be represented as in the figure given below.

While declaring string, size is not mandatory. So we can write the above code as given below:

Char ch[]={,’n’,’l’,’i’,’n’,’e’,’s’,’m’,’a’,’r’,’t’,’t’,’r’,’a’,’i’,’n’,’e’,’r’,’\0’}

We can also define the string by the string literal in C language. For example: char
str[]=”onlinemarttrainer”;

In such case, ‘\0’ will be appended at the end of the string by the compiler.

(b) AND operation


There are two inputs and one output in binary AND operation. The inputs and result to a binary
AND operation can only be 0 or 1. The binary AND operation will always produce a 1 output
if both inputs are 1 and will produce a 0 output if both inputs are 0. For two different inputs,
the output will be 0.
lOMoARcPSD|199 248 80

AND Truth table

Input Output
X Y
0 0 0
0 1 0
1 0 0
1 1 1

C) XOR operation
There are two inputs and one output in binary XOR (exclusive OR) operation. It is similar to
ADD operation which takes two inputs and produces one result. i.e. one output. The inputs and
result to a binary AND operation can only be 0 or 1. The binary XOR operation will always
produce a 1 output if either of its inputs are 1 and will produce a 0 output if both inputs are 0 or
1.

XOR Truth table

Input Output
X Y
0 0 0
0 1 1
1 0 1
1 1 0

ALGORITHM:

STEP-1: Define the string


STEP-2: Perform AND operation
STEP-3: Perform XOR operation
STEP4: Display the result

CONCLUSION: Thus the AND or and XOR a string with a 127 had been implemented
successfully using C language.
lOMoARcPSD|199 248 80

EX.NO:2

PERFORM ENCRYPTION AND DECRYPTION USING THE METHOD OF RAILFENCE–


ROW & COLUMN
TRANSPOSITION TECHNIQUE.
AIM:

Write a Java/C/C++/Python program to perform encryption and decryption using the method of
Transposition technique

DESCRIPTION:

In the rail fence cipher, the plain text is written downwards and diagonally on successive "rails"
of an imaginary fence, then moving up when were ach the bottom rail. When were ach the to p
rail, the message is written downwards again until the whole plain text is written out. The
message is then read off in rows.

EXAMPLE:

ALGORITHM:

STEP-1: Read the Plain text.


STEP-2: Arrange the plain text in row column are matrix format.
STEP-3: Now read the keyword depending on the number of columns of the plain text.
STEP4: Arrange the characters of the key word in sorted order and the corresponding columns
of the plain text.
STEP-5: Read the characters row wise or column wise in the former order to get the
cipher text.

CONCLUSION:
Thus the railfence transposition algorithm had been executed successfully.
lOMoARcPSD|199 248 80

EX.NO:3
IMPLEMENTATION OF DES

AIM:

Write a Java/C/C++/Python program to implement DES algorithm.

DESCRIPTION:

DES is a symmetric encryption system that uses64-bitblocks, 8bits of which are used
for parity checks. The key therefore has a "useful" length of 56bits, which means that only 56
bits are actually used in the algorithm. The algorithm involves carrying out combinations,
substitutions and permutations between the text to be encrypted and the key, while making sure
the operations can be performed in both directions. The key is ciphered on 64 bits and made of
16 blocks of 4 bits, generally denoted k1 to k16. Given that "only" 56 bits are actually used for
encrypting, there can be 256 different keys.

The main parts of the algorithm are as follows:


➢ Fractioning of the text into 64-bit blocks
➢ Initial permutation of blocks
➢ Break down of the blocks into two parts: left and right ,named L and R
➢ Permutation and substitution steps repeated 16 times
➢ Re-joining of the left and right parts then inverse initial permutation

EXAMPLE:
lOMoARcPSD|199 248 80

Data Encryption Standard (DES)

The Data Encryption Standard (DES) is a Symmetric-key block cipher issued by the national
Institute of Standards & Technology (NIST).
DES is an implementation of a Feistel Cipher. It uses 16 round Feistel structure. The
block size is 64-bit. Though, key length is 64-bit, DES has an effective key length of 56 bits,
since 8 of the 64 bits of the key are not used by the encryption algorithm (function as check
bits only). General Structure of DES is depicted in the following illustration −

Figure 3.1: General Structure of DES

Since DES is based on the Feistel Cipher, all that is required to specify DES is −

• Round function
• Key schedule
• Any additional processing − Initial and final permutation

Initial and Final Permutation

The initial and final permutations are straight Permutation boxes (P-boxes) that are
inverses of each other. They have no cryptography significance in DES. The initial and final
permutations are shown as follows
lOMoARcPSD|199 248 80

Figure 3.2 initial and final permutations

Round Function
The heart of this cipher is the DES function, f. The DES function applies a 48-bit key to
the rightmost 32 bits to produce a 32-bit output.

Figure 3.3 Round Functions

Expansion Permutation Box


Since right input is 32-bit and round key is a 48-bit, we first need to expand right
input to 48 bits.

Permutation logic is graphically depicted in the following illustration:

Figure 3.4 Permutation logic


lOMoARcPSD|199 248 80

The graphically depicted Permutation logic is generally described as table in DES


specification illustrated as shown:
Table 3.1 Permutation logic

XOR(Whitener)

After the expansion permutation, DES does XOR operation on the expanded right
section and the round key. The round key is used only in this operation.

Substitution Boxes

The S-boxes carry out the real mixing (confusion). DES uses 8 S-boxes, each with a 6-
bit input and

a 4-bit output. Refer the following illustration –

Figure 3.5 S-Boxes

The S-box rule is illustrated below –

Figure 3.6 S-Box Rules


lOMoARcPSD|199 248 80

There are a total of eight S-box tables. The output of all eight s-boxes is then combined in to
32 bit section.

Straight Permutation − The 32 bit output of S-boxes is then subjected to the straight
permutation with rule shown in the following illustration:

Table 3.2 Straight Permutation

Key Generation
The round-key generator creates sixteen 48-bit keys out of a 56-bit cipher key. The
process of key generation is depicted in the following illustration −

Figure 3.7 the process of key generation


lOMoARcPSD|199 248 80

The logic for Parity drops, shifting, and Compression P-box is given in the DES
description

DES Analysis
The DES satisfies both the desired properties of block cipher. These two properties
make cipher very strong.
•Avalanche effect − A small change in plaintext results in the very great change in the cipher
text.
•Completeness − Each bit of cipher text depends on many bits of plaintext.
During the last few years, cryptanalysis has found some weaknesses in DES when key
selected are weak keys. These keys shall be avoided.
DES has proved to be a very well designed block cipher. There have been no significant
cryptanalytic attacks on DES other than exhaustive key search.

ALGORITHM:

STEP-1: Read the 64-bit plain text.


STEP-2: Split it into two 32-bit blocks and store it in two different arrays.
STEP-3: Perform XOR operation between these two arrays.
STEP-4: The output obtained is stored as the second 32-bit sequence and the original
second 32-bit sequence forms the first part.
STEP-5: Thus the encrypted 64-bit cipher text is obtained in this way. Repeat the same process
for the remaining plain text characters.

CONCLUSION:

Thus the data encryption standard algorithm had been implemented successfully
using Java language.
lOMoARcPSD|199 248 80

EX.NO:4
IMPLEMENTATION OF AES

AIM:

Write a Java/C/C++/Python program to implement AES algorithm.

DESCRIPTION:

Theory Concepts:

The more popular and widely adopted symmetric encryption algorithm likely to be encountered
nowadays is the Advanced Encryption Standard (AES). It is found at least six times faster than triple
DES.
A replacement for DES was needed as its key size was too small. With increasing computing power,
it was considered vulnerable against exhaustive key search attack. Triple DES was designed to
overcome this drawback but it was found slow.

The features of AES are as follows −

• Symmetric key symmetric block cipher


• 128-bit data, 128/192/256-bit keys
• Stronger and faster than Triple-DES
• Provide full specification and design details
• Software implementable in C ,Java and Python

Operation of AES

AES is an iterative rather than Feistel cipher. It is based on ‘substitution–permutation network’.


It comprises of a series of linked operations, some of which involve replacing inputs by specific
outputs (substitutions) and others involve shuffling bits around (permutations).
Interestingly, AES performs all its computations on bytes rather than bits. Hence, AES treats the 128
bits of a plaintext block as 16 bytes. These 16 bytes are arranged in four columns and four rows for
processing as a matrix −

Unlike DES, the number of rounds in AES is variable and depends on the length of the key.
AES uses 10 rounds for 128-bit keys, 12 rounds for 192-bit keys and 14 rounds for 256-bit keys.
Each of these rounds uses a different 128-bit round key, which is calculated from the original AES
key.
lOMoARcPSD|199 248 80

The schematic of AES structure is given in the following illustration −

Figure 4.1 AES structure


Encryption Process

Here, we restrict to description of a typical round of AES encryption. Each round comprise of
four sub-processes. The first round process is depicted below −
lOMoARcPSD|199 248 80

CONCLUSION:

Thus the Advanced encryption standard algorithm had been implemented successfully using Java language
EX.NO:5
IMPLEMENTATION OF RSA

AIM:

To write a C program to implement the RSA encryption algorithm.

DESCRIPTION:

RSA is an algorithm used by modern computers to encrypt and decrypt messages. It is


an asymmetric cryptographic algorithm. Asymmetric means that there are two different keys.
This is also called public key cryptography, because one of them can be given to everyone. A
basic principle behind RSA is the observation that it is practical to find three very large
positive integers e, d and n such that with modular exponentiation for all integer m:

(me)d=m(modn)

The public key is represented by the integers n and e; and, the private key, by the
integer d. m represents the message. RSA involves a public key and a private key. The public
key can be known by everyone and is used for encrypting messages. The intention is that
messages encrypted with the public key can only be decrypted in a reasonable amount of time
using the private key.

RSA(Rivest, Shamir & Adleman )


RSA is an algorithm used by modern computers to encrypt and decrypt messages. It is
an asymmetric cryptographic algorithm. Asymmetric means that there are two different keys.
This is also called public key cryptography, because one of the keys can be given to anyone.
The other key must be kept private. The algorithm is based on the fact that finding the factors
of a large composite number is difficult: when the integers are prime numbers, the problem is
called prime factorization. It is also a key pair (public and private key) generator.

• RSA makes the public and prívate keys by multiplying two large prime numbers p and
q
▫ It’s easy to find & multiply large prime No. (n=pq)
▫ It is very difficult to factor the number n to find p and q
▫ Finding the private key from the public key would require a factoring operation
▫ The real challenge is the selection & generation of keys.
• RSA is complex and slow, but secure
• 100 times slower than DES on s/w & 1000 times on h/w

The Rivest-Shamir-Adleman (RSA) algorithm is one of the most popular and secures public-
key encryption methods. The algorithm capitalizes on the fact that there is no efficient way to
factor very large (100-200 digit) numbers.

Using an encryption key (e,n), the algorithm is as follows:

1. Represent the message as an integer between 0 and (n-1). Large messages can be broken up
into a number of blocks. Each block would then be represented by an integer in the same
range.
2. Encrypt the message by raising it to the eth power modulo n. The result is a ciphertext
message C.
3. To decrypt ciphertext message C, raise it to another power d modulo n

The encryption key (e,n) is made public. The decryption key (d,n) is kept private by
the user.

How to Determine Appropriate Values for e, d, and n

1. Choose two very large (100+ digit) prime numbers. Denote these numbers as p and q.
2. Set n equal to p * q.
3. Choose any large integer, d, such that GCD(d, ((p-1) * (q-1))) = 1
4. Find e such that e * d = 1 (mod ((p-1) * (q-1)))

Rivest, Shamir, and Adleman provide efficient algorithms for each required
operation[4].

How secure is a communication using RSA?


Cryptographic methods cannot be proven secure. Instead, the only test is to see if someone can
figure out how to decipher a message without having direct knowledge of the decryption key. The
RSA method's security rests on the fact that it is extremely difficult to factor very large numbers.
If 100 digit numbers are used for p and q, the resulting n will be approximately 200 digits. The
fastest known factoring algorithm would take far too long for an attacker to ever break the code.
Other methods for determining d without factoring n are equally as difficult.

Any cryptographic technique which can resist a concerted attack is regarded as secure. At this
point in time, the RSA algorithm is considered secure.

How Does RSA Works?

RSA is an asymmetric system, which means that a key pair will be generated (we will see how
soon) , a public key and a private key , obviously you keep your private key secure and pass
around the public one.

The algorithm was published in the 70’s by Ron Rivest, Adi Shamir, and Leonard Adleman,
hence RSA, and it sort of implement’s a trapdoor function such as Diffie’s one.

RSA is rather slow so it’s hardly used to encrypt data, more frequently it is used to encrypt and
pass around symmetric keys which can actually deal with encryption at a faster speed.

RSA Security:
• It uses prime number theory which makes it difficult to find out the key by reverse
engineering.
• Mathematical Research suggests that it would take more than 70 years to find P & Q if
N is a 100 digit number.

Algorithm

The RSA algorithm holds the following features −

 RSA algorithm is a popular exponentiation in a finite field over integers including prime
numbers.
 The integers used by this method are sufficiently large making it difficult to solve.
 There are two sets of keys in this algorithm: private key and public key.
You will have to go through the following steps to work on RSA algorithm −
Step 1: Generate the RSA modulus

The initial procedure begins with selection of two prime numbers namely p and q, and then
calculating their product N, as shown −

N=p*q

Here, let N be the specified large number.

Step 2: Derived Number (e)

Consider number e as a derived number which should be greater than 1 and less than (p-1) and (q-
1). The primary condition will be that there should be no common factor of (p-1) and (q-1) except
1

Step 3: Public key

The specified pair of numbers n and e forms the RSA public key and it is made public.

Step 4: Private Key


Private Key d is calculated from the numbers p, q and e. The mathematical relationship between
the numbers is as follows −

ed = 1 mod (p-1) (q-1)

The above formula is the basic formula for Extended Euclidean Algorithm, which takes p and q as
the input parameters.

Encryption Formula

Consider a sender who sends the plain text message to someone whose public key is (n,e). To
encrypt the plain text message in the given scenario, use the following syntax −
C = Pe mod n
Decryption Formula

The decryption process is very straightforward and includes analytics for calculation in a
systematic approach. Considering receiver C has the private key d, the result modulus will be
calculated as −
Plaintext = Cd mod n

Example

1. P=7, Q=17
2. 119=7*17
3. (7-1)*(17-1)= 6*16 =96 factor 2 & 3, so E=5
4. (D*5) mod (7-1)*(17-1)=1, so D=77
5. CT=105 mod 119 =100000 mod 119 =40
6. Send 40
7. PT=4077 mod 119 = 10
ALGORITHM:

STEP-1: Select two co-prime numbers as p and q.


STEP-2: Compute n as the product of p and q.
STEP-3: Compute (p-1)*(q-1) and store it in z.
STEP-4: Select a random prime number e that is less than that of z.
STEP-5: Compute the private key,dase*mod-1(z).

STEP-6: The cipher text is computed as messagee*mod n.


STEP-7: Decryption is done as cipherd mod n.

CONCLUSION:

Thus we learn that to how to Encrypt and Decrypt the message by using RSA Algorithm.
EX.NO:6

IMPLEMENTATION OF DIFFIEHELLMAN KEY EXCHANGE ALGORITHM


AIM:

To implement the Diffie-Hellman Key Exchange algorithm using C language.

DESCRIPTION:

Diffie–Hellman Key Exchange establishes a shared secret between two parties that can be used
for secret communication for exchanging data over a public network. It is primarily used as a method of
exchanging cryptography keys for use in symmetric encryption algorithms like AES. The algorithm in
itself is very simple. The process begins by having the two parties, Alice and Bob. Let's assume that
Alice wants to establish a shared secret with Bob.

Diffie-Hellman key Exchange (DH)

In the mid- 1970’s, Whitefield Diffie, a student at the Stanford University met with Martin
Hellman, his professor &the two began to think about it. After some research & complicated
mathematical analysis, they came up with the idea of AKC. Many experts believe that this development
is the first & perhaps the only truly revolutionary concept in the history of cryptography

Silent Features of Diffie-Hellman key Exchange (DH)


1. Developed to address shortfalls of key distribution in symmetric key distribution.
2. A key exchange algorithm, not an encryption algorithm
3. Allows two users to share a secret key securely over a public network
4. Once the key has been shared Then both parties can use it to encrypt and decrypt messages using
symmetric cryptography
5. Algorithm is based on “difficulty of calculating discrete logarithms in a finite field”
6. These keys are mathematically related to each other.
7. ‘’Using the public key of users, the session key is generated without transmitting the private key of the
users.’’
Diffie-Hellman Key Exchange/Agreement Algorithm with Example

Diffie -Hellman Key exchange

1. Public values:

 large prime p, generator g (primitive root of p)

2. Alice has secret value x, Bob has secret y

3. Discrete logarithm problem: given x, g,


and n, find A

4. A  B: gx (mod n)

5. B  A: gy (mod n)

6. Bob computes (gx)y = gxy(mod n)

7. Alice computes (gy)x = gxy (mod n)

8. Symmetric key= gxy (mod n)


Limitation: Vulnerable to “man in the middle” attacks*

EXAMPLE:

ALGORITHM:

STEP-1: Both Alice and Bob shares the same public keys g and p.
STEP-2: Alice selects a random public key a.
STEP-3: Alice computes his secret key A as ga mod p.
STEP-4: Then Alice sends A to Bob.
STEP-5: Similarly Bob also selects a public key b and computes his secret key as B
and sends the same back to Alice.
STEP-6 :Now both of them compute their common secret key as the other one’s secret
key power of a mod p.

CONCLUSION:
Thus we have studied and implement Diffie-Hellmen key exchange algorithm
lOMoARcPSD|199 248 80

EX.NO:7
IMPLEMENTATION OF MD5

AIM:

To write a C program to implement the MD5 hashing technique.

DESCRIPTION:

MD5 processes a variable-length message into a fixed-length output of 128 bits. The
input message is broken up into chunks of 512-bit blocks. The message is padded so that its
length is divisible by 512.The padding works as follows: first a single bit ,1 ,is appended to the
end of the message. This is followed by as many zeros as are required to bring the length of the
message upto 64 bits less than a multiple of 512.The remaining bits are filled up with
64bits representing the length of the original message, modulo 264.
The main MD 5 algorithm
operates on a 128-bit state, divided into four 32-bit words, denoted A, B, C, and D. These are
initialized to certain fixed constants. The main algorithm then uses each 512-bit message block
in turn to modify the state.

EXAMPLE:

ALGORITHM:

STEP-1: Read the 128-bit plain text.


STEP-2: Divide into four blocks of 32-bits named as A,B,C and D.
lOMoARcPSD|199 248 80

STEP3: Compute the functions f, g, hand I with operations such as, rotations,
permutations, etc,.
STEP4:The output of these functions are combined together as F and performed
circular shifting and then given to key round.
STEP-5: Finally, right shift of‘ s’times are performed and the results are combined
together to produce the final output.

CONCLUSION:
Thus we have studied and implement of MD5 hashing algorithm
lOMoARcPSD|199 248 80

You might also like