0% found this document useful (0 votes)
285 views23 pages

Experiment: 1 Euclidean and Extended Euclidean Algorithm

The RSA algorithm uses a public and private key pair to encrypt and decrypt messages. The public key is used to encrypt messages and the private key is used to decrypt them. Keys are generated by choosing two prime numbers and performing mathematical operations including modular exponentiation. Encryption involves exponentiating the message with the public key. Decryption involves exponentiating the ciphertext with the private key to recover the original message.

Uploaded by

William
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)
285 views23 pages

Experiment: 1 Euclidean and Extended Euclidean Algorithm

The RSA algorithm uses a public and private key pair to encrypt and decrypt messages. The public key is used to encrypt messages and the private key is used to decrypt them. Keys are generated by choosing two prime numbers and performing mathematical operations including modular exponentiation. Encryption involves exponentiating the message with the public key. Decryption involves exponentiating the ciphertext with the private key to recover the original message.

Uploaded by

William
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/ 23

Experiment : 1

Euclidean and extended Euclidean Algorithm


Aim: Implement Euclidean and extended Euclidean Algorithm

I. Euclidean Algorithm
The Euclidean Algorithm finds greatest common divisor (GCD) of two positive integers for
large numbers.
Algorithm:
Extended_ Euclidean (a,b)

{
r1 a; r2b;
while(r2>0)
{
qr1 / r2;
rr1 – q*r2;
r1r2;
r2r;
}
GCD(a,b) r1
}

II. Extended Euclidean Algorithm


The Extended Euclidean algorithm finds the multiplicative inverse of b in Zn. When n and b
are given and gcd(n,b)=1.
Algorithm: Extended_Euclidean(n,b)

{
r1 n; r2b;
t10; t2 1;
while(r2>0)
{

qr1 / r2;
rr1 – q*r2;
1
r1r2;
r2r;
tt1 – q*t2;
t1t2;
t2t;
}
if(r1==1)
{

if(t1<0)
{
b-1  t1+ n

}
else
b-1  t1;

}
else
print "Inverse is not Possible”
}

The logic is to be implemented using Turbo++ or Java.

Exercise(Given to the students):

i) Find the Greatest Commmon


Divisor(GCD) of 2750 and 1760

ii) Find the multiplicative inverse of 8 in Z10

iii) Find the multiplicative inverse of 23 in Z100

2
Experiment : 2
Double transposition cipher
Aim: To implement a double transposition cipher
Theory:
In cryptography, 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 cipher text constitutes a permutation of
the plaintext. That is, the order of the units is changed. Mathematically a bijective function is
used on the characters' positions to encrypt and an inverse function to decrypt.
A different key can be used in each step, but normally the same key is used.

The logic for double transposition cipher is to be implemented using Turbo++ or Java.

Exercise:
Encrypt the message “this is my lab experiment” using the above cipher.
Ignore the space between words. Decrypt the message to get the original
plaintext.

3
Experiment : 3
Additive Cipher
Aim: Implement Additive cipher

Background

The simplest monoalphabetic cipher is the additive cipher. This cipher is sometimes called a
shift cipher and sometimes a Caesar cipher, but the term additive cipher better reveals its
mathematical nature.
Plaintext and ciphertext in Z26

Encrption and Decryption of Additive cipher

Example:
Use the additive cipher with key = 15 to encrypt the message “hello”.

Solution

We apply the encryption algorithm to the plaintext, character by character:

Use the additive cipher with key = 15 to decrypt the message “WTAAD”.

4
Solution

We apply the decryption algorithm to the plaintext character by character:

Security:

The key length is identical to the size of the given alphabet. Using the capital letters A-Z as
alphabet allows 26 different keys, with the 26th key rendered meaningless because it would map
each letter to itself.

Cryptanalysis : The art or process of deciphering coded messages without knowing the key.
technique of trying every possible decryption key is called a brute-force attack. correct one is
found (brute-force analysis). The Caesar cipher can also easily be cracked with a frequency-
analysis.

Kerckhoffs’s Principle : “The enemy knows the system.” a cipher should still be secure even if
everyone else knows how the cipher works and has the ciphertext (that is, everything except the
key).

The logic for Additive cipher is to be implemented using Turbo++ or Java.

Exercise:
Encrypt the message “this is an exercise” using Additive cipher. Ignore the
space between words. Decrypt the message to get the original plaintext.

5
Experiment : 4
Brute Force Attack

Aim: Apply brute force attack on the above cipher(Additive cipher)

Background

In cryptography,a brute-force attack consists of an attacker trying


any passwords or passphrases with the hope of eventually guessing correctly. The attacker
systematically checks all possible passwords and passphrases until the correct one is found.
Alternatively, the attacker can attempt to guess the key which is typically created from the
password using a key derivation function. This is known as an exhaustive key search.
A brute-force attack is a cryptanalytic attack that can, in theory, be used to attempt to decrypt
any encrypted data[1] (except for data encrypted in an information-theoretically
secure manner). Such an attack might be used when it is not possible to take advantage of
other weaknesses in an encryption system (if any exist) that would make the task easier.
When password guessing, this method is very fast when used to check all short passwords,
but for longer passwords other methods such as the dictionary attack are used because a
brute-force search takes too long. Longer passwords, passphrases and keys have more
possible values, making them exponentially more difficult to crack than shorter ones.
Brute-force attacks can be made less effective by obfuscating the data to be encoded making
it more difficult for an attacker to recognize when the code has been cracked or by making
the attacker do more work to test each guess. One of the measures of the strength of an
encryption system is how long it would theoretically take an attacker to mount a successful
brute-force attack against it.

The logic for Brute force attack is to be implemented using Turbo++ or Java.

Example

Eve has intercepted the ciphertext “UVACLYFZLJBYL”. Show how she can use a brute-
force attack to break the cipher.
Eve tries keys from 1 to 7. With a key of 7, the plaintext is “not very secure”, which makes
sense.

6
7
Experiment : 5
RSA Algorithm

Aim: To implement RSA algorithm to achieve confidentiality

Theory:

Public-key cryptography refers to a cryptographic system requiring two


separate keys, one to lock or encrypt the plaintext, and one to unlock or decrypt
the cypher text. Neither key will do both functions. One of these keys is
published or public and the other is kept private. If the lock/encryption key is
the one published then the system enables private communication from the
public to the unlocking key's owner. If the unlock/decryption key is the one
published then the system serves as a signature verifier of documents locked by
the owner of the private key. This cryptographic approach uses asymmetric
key algorithms such as RSA, hence the more general name of "asymmetric key
cryptography". Some of these algorithms have the public key/private key
property; that is, neither key is derivable from knowledge of the other; not all
asymmetric key algorithms do. Those with this property are particularly useful
and have been widely deployed, and are the source of the commonly used name.

Although unrelated, the key pair are mathematically linked. The public key is
used to transform a message into an unreadable form, decryptable only by using
the (different but matching) private key. By publishing the public key, the key
producer empowers anyone who gets a copy of the public key to produce
messages only s/he can read—because only the key producer has a copy of the
private key (required for decryption). When someone wants to send a secure
message to the creator of those keys, the sender encrypts it (i.e., transforms it
into an unreadable form) using the intended recipient's public key; to decrypt

8
the message, the recipient uses the private key. No one else, including the
sender, can do so.

RSA

RSA involves a public key and a private key. The public key can be known to
everyone and is used for encrypting messages. Messages encrypted with the
public key can only be decrypted using the private key. The keys for the RSA
algorithm are generated the following way:

1. Choose two distinct prime numbers p and q.


2. For security purposes, the integers p and q should be chosen at random,
and should be of similar bit-length.
3. Compute n = pq.
 n is used as the modulus for both the public and private keys
4. Compute φ(n) = (p-1)(q-1), where φ is Euler's totient function.
5. Choose an integer e such that 1 < e < φ(n) and greatest common divisor
of (e, φ(n)) = 1; i.e., e and φ(n) are co prime.
 e is released as the public key exponent.
6. Determine d as:

i.e., d is the multiplicative inverse of e mod φ(n).


The public key consists of the modulus n and the public (or encryption)
exponent e. The private key consists of the modulus n and the private (or
decryption) exponent d which must be kept secret.
Encryption
Alice transmits her public key to Bob and keeps the private key secret.
Bob then wishes to send message M to Alice.
He first turns M into an integer m, such that by using an
agreed-upon reversible protocol known as a padding scheme. He then
computes the ciphertext corresponding to
.
This can be done quickly using the method of exponentiation by
squaring. Bob then transmits to Alice.
Note that at least nine values of m will yield a cipher text c equal to
m but this is very unlikely to occur in practice.

9
Decryption
Alice can recover from by using her private key exponent via
computing
.

Example:
Jennifer creates a pair of keys for herself. She chooses p = 397 and q = 401. She calculates n =
159197. She then calculates f(n) = 158400. She then chooses e = 343 and d = 12007. Show how
Ted can send a message to Jennifer if he knows e and n.
Suppose Ted wants to send the message “NO” to Jennifer. He changes each character to a
number (from 00 to 25), with each character coded as two digits. He then concatenates the two
coded characters and gets a four-digit number. The plaintext is 1314. Figure below shows the

Exercise:

In RSA:

a. Given n=221, and e=5, find d.


b. Given n=3937, and e=17, find d.
c. Given p=19, q=23, and e=3, find n, phi(n) and d.

10
Experiment :6
Knapsack crypto system
Aim: To implement Knapsack crypto system

Theory:

One of the earliest public key cryptosystems is the knapsack cryptosystem, first
described by Ralph Merkle & Martin Hellman in 1978 and the underlying scheme
implements the subset sum problem. As stated before, the subset sum problem can
be unsolvable, however, there are still instances of the problem that are solvable.
The basic idea of the Merkle-Hellman scheme is in transforming hard or unfeasible
subset sum problems into easy subset sum problems.

Enciphering and Deciphering

Suppose Bob wants to send a message to Alice, and Alice's public key is a = (a1,
a2, ..., an). To encipher a message x = (x1, x2, ..., xn) of n bits, Bob makes the sum:

S is then sent to Alice. If the message is long it can be split up into blocks of n bits,
padding the last block with zeros if necessary. Since the enciphering key is made
public and S can potentially be eavesdropped, then
extracting x from S and a should intentionally be hard. If a is chosen to be a
sequence of integers, then Alice can usually not find x in a reasonable amount of
CPU time or the task is just NP-hard. This is because the only way to find x is to
try all 2n possible values of x if equation 1 is satisfied, which is unfeasible if n is
say greater than 100. This makes eavesdropping a somewhat trivial concern and
consequently making it even harder to find x.

If a is chosen randomly by Alice, it will also be hardly possible for her to


decipher S and find the plaintext x. This is where the Merkle-Hellman trapdoor
comes into play. It allows Alice to overcome the infeasibility of
11
finding x given S and gives her some secret information. The secret information is
called the deciphering key. The trapdoor information is taken into consideration
when Alice creates her public key. As it turns out, it is precisely the use of the
trapdoor technique that makes the scheme insecure.

It should be noted that S must be a one-to-one function because if there are two
different plaintexts x and y that give the same ciphertext, the receiver cannot
uniquely recover the plaintext.

The Merkle-Hellman Trapdoor

When Alice constructed her public enciphering key a, she first generated a super-

increasing sequence of natural numbers . The vector is


said to be a super increasing sequence if for each i, with ,

In words, a super-increasing sequence is when each term is greater than the sum of
the previous terms. For example, (1, 2, 4, 8, ..., 2n-1) is a super-increasing sequence
and is considered an "easy" sequence and (1, 2, 3, 4, 5,...,9) is not a super-
increasing sequence. To determine if a sequence is super- increasing a computer
only has to make one pass over the whole sequence which takes O(h) time. So in
deciding whether a subset sum, T, is part of a super- increasing set, the computer
must find the largest number in the set less than or equal to T and subtract it to get
T'. It repeats this process with T'. If T' ends up to be zero, then the subset sum
consists of all the numbers subtracted from T.

To decipher the encrypted message, Alice must calculate using S and


the deciphering key, where

12
and

So letting h = n, if , then xh has to be one, otherwise it is zero. Then Alice


continues iteratively, subtracting xhah from S1, with h decrementing from n to 1
during the iterations.

Exercise:

Given the super increasing tuple b=[7,11,23,43,87,173,357], r=41, and modulus


n=1001, encrypt and decrypt the letter “a” using knapsack crypto system. Use [7
6 5 1 2 3 4] as the permutation table.

13
Experiment : 7
Diffie-Hellman key exchange
Aim: Demonstrate how Diffie-Hellman key exchange works

Theory:

Diffie Hellman key exchange algorithm uses asymmetric key principles for the
distribution of symmetric keys to both parties in a communication network. Key
distribution is an important aspect of conventional algorithm and the entire
safety is dependent on the distribution of key using secured channel. 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, a mod p , a2 mod p , a 3 mod
p, .............. ap-1 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 < q


Calculate the public key YA where YA = aXA mod q

14
Step 3 : KEY GENERATION BY USER 'B'

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

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

Step 5 : SYMMETRIC KEY (K) GENERATION BY USER 'A'

K= YB XA mod q

Step 6 : SYMMETRIC KEY (K) GENERATION BY USER 'B'

K= YA XB mod q

It can be easily be proved that the key K generated by this algorithm by both
parties are the same.

Students are required to implement the logic in Turbo C++ or Java.

15
Experiment : 8
MD-5 algorithm
Aim: To study MD-5 algorithm

Theory: In cryptography, MD5 (Message-Digest algorithm 5) is a widely used cryptographic


hash function with a 128-bit hash value. As an Internet standard (RFC 1321), MD5 has been
employed in a wide variety of security applications, and is also commonly used to check the
integrity of files. However, it has been shown that MD5 is not collision resistant. Hence
MD5 is not suitable for applications that rely on this property. An MD5 hash is typically
expressed as a 32 digit hexadecimal number.
MD5 was designed by Ron Rivest in 1991 to replace an earlier hash function, MD4. In 1996,
a flaw was found with the design of MD5.
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 up to 64 bits fewer than a multiple of 512. The remaining bits are filled up with a
64-bit integer representing the length of the original message, in bits.
The main MD5 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
operates on each 512-bit message block in turn, each block modifying the state. The
processing of a message block consists of four similar stages, termed rounds; each round is
composed of 16 similar operations based on a non-linear function F, modular addition, and
left rotation.

16
Implementation details:

• Step1 Append padding bits

The input message is "padded" (extended) so that its length (in bits)
equals to 448 mod 512. Padding is always performed, even if the length of the
message is already 448 mod 512.

Padding is performed as follows: a single "1" bit is appended to the


message, and then "0" bits are appended so that the length in bits of the padded
message becomes congruent to 448 mod 512. At least one bit and at most 512
bits are appended.

• Step2. Append length

A 64-bit representation of the length of the message is appended to the


result of step1. If the length of the message is greater than 2^64, only the low-
order 64 bits will be used.

The resulting message (after padding with bits and with b) has a length
that is an exact multiple of 512 bits. The input message will have a length that is
an exact multiple of 16 (32-bit) words.

17
• Step3. Initialize MD buffer

A four-word buffer (A, B, C, D) is used to compute the message digest.


Each of A, B, C, D is a 32-bit register. These registers are initialized to the
following values in hexadecimal, low-order bytes first):

word A: 01 23 45 67

word B: 89 ab cd ef

word C: fe dc ba 98

word D: 76 54 32 10

• Step4. Process message in 16-word blocks

Four functions will be defined such that each function takes an input of
three 32-bit words and produces a 32-bit word output.

F (X, Y, Z) = XY or not (X) Z

G (X, Y, Z) = XZ or Y not (Z)

H (X, Y, Z) = X xor Y xor Z

I (X, Y, Z) = Y xor (X or not (Z))

Round 1.

[abcd k s i] denote the operation a = b + ((a + F (b, c, d) + X [k] + T [i]) <<< s).

Do the following 16 operations.

[ABCD 0 7 1] [DABC 1 12 2] [CDAB 2 17 3] [BCDA 3 22 4]

[ABCD 4 7 5] [DABC 5 12 6] [CDAB 6 17 7] [BCDA 7 22 8]

[ABCD 8 7 9] [DABC 9 12 10] [CDAB 10 17 11] [BCDA 11 22 12]

[ABCD 12 7 13] [DABC 13 12 14] [CDAB 14 17 15] [BCDA 15 22 16]

18
MD5 vs. MD4

• A fourth round has been added.

• Each step has a unique additive constant.

• The function g in round 2 was changed from (XY v XZ v YZ) to (XZ v Y


not(Z)).

• Each step adds in the result of the previous step.

• The order in which input words are accessed in rounds 2 and 3 is


changed.

• The shift amounts in each round have been optimized. The shifts in
different rounds are distinct.

19
Experiment : 9
S-DES symmetric encryption

Aim: Implement S-DES symmetric encryption Algorithm.


Theory :

General structure of S-DES Encryption cipher

Assume input 10-bit key, K, is: 1010000010


Then the steps for generating the two 8-bit round keys, K1 and K2, are:
1. Rearrange K using P10: 1000001100
2. Left shift by 1 position both the left and right halves: 00001 11000
3. Rearrange the halves with P8 to produce K1: 10100100
4. Left shift by 2 positions the left and right halves: 00100 00011
5. Rearrange the halves with P8 to produce K2: 01000011
K1 and K2 are used as inputs in the encryption and decryption stages.
Assume a 8-bit plaintext, P: 01110010
Then the steps for encryption are:
1. Apply the initial permutation, IP, on P: 10101001
2. Assume the input from step 1 is in two halves, L and R: L=1010, R=1001
3. Expand and permutate R using E/P: 11000011
4. XOR input from step 3 with K1: 10100100 XOR 11000011 = 01100111
5. Input left halve of step 4 into S-Box S0 and right halve into S-Box S1:
a. For S0: 0110 as input: b1,b4 for row, b2,b3 for column

20
b. Row 00, column 11 -> output is 10
c. For S1: 0111 as input:
d. Row 01, column 11 -> output is 11
6. Rearrange outputs from step 5 (1011) using P4: 0111
7. XOR output from step 6 with L from step 2: 0111 XOR 1010 = 1101
8. Now we have the output of step 7 as the left half and the original R as the right half.
Switch the halves and move to round 2: 1001 1101
9. E/P with right half: E/P(1101) = 11101011
10. XOR output of step 9 with K2: 11101011 XOR 01000011 = 10101000
11. Input to s-boxes:
a. For S0, 1010
b. Row 10, column 01 -> output is 10
c. For S1, 1000
d. Row 10, column 00 -> output is 11
12. Rearrange output from step 11 (1011) using P4: 0111
13. XOR output of step 12 with left halve from step 8: 0111 XOR 1001 = 1110
14. Input output from step 13 and right halve from step 8 into inverse IP
a. Input us 1110 1101
b. Output is: 01110111
So our encrypted result of plaintext 01110010 with key 1010000010 is: 01110111

21
Experiment : 10
Implement Virus/Antivirus

Aim: Implement Virus/Antivirus.

VIRUS (Vital Information Resources Under Seize): A computer virus is a program or piece of
code that is loaded onto your computer without your knowledge and runs against your wishes.
What Does Computer virus do?
Through the course of using the Internet and your computer, you may have come in to contact with
computer viruses. Many computer viruses are stopped before they can start, but there is still an ever
growing concern as to what do computer viruses do and the list of common computer virus
symptoms. A computer virus might corrupt or delete data on your computer, use your email program
to spread itself to other computers, or even erase everything on your hard disk.
Computer viruses are often spread by attachments in email messages or instant messaging messages.
That is why it is essential that you never open email attachments unless you know who it's from and
you are expecting it.
Viruses can be disguised as attachments of funny images, greeting cards, or audio and video files.
Computer viruses also spread through downloads on the Internet. They can be hidden in illicit
software or other files or programs you might download.
Classification of virus according to it’s working
Macro viruses: A macro is a piece of code that can be embedded in a data file. A macro virus is thus
a virus that exists as a macro attached to a data file. In most respects, macro viruses are like all other
viruses. The main difference is that they are attached to data files (i.e., documents) rather than
executable programs. Document-based viruses are, and will likely continue to be, more prevalent
than any other type of virus.
Worms: Worms are very similar to viruses in that they are computer programs that replicate
functional copies of themselves (usually to other computer systems via network connections) and
often, but not always, contain some functionality that will interfere with the normal use of a
computer or a program. Unlike viruses, however, worms exist as separate entities; they do not attach
themselves to other files or programs. Because of their similarity to viruses, worms also are often
referred to as viruses.

22
Trojan horses: A Trojan horse is a program that does something undocumented which the
programmer intended, but that users would not accept if they knew about it. By some definitions, a
virus is a particular case of a Trojan horse, namely, one which is able to spread to other programs
(i.e., it turns them into Trojans too). According to others, a virus that does not do any deliberate
damage (other than merely replicating) is not a Trojan.

Finally, despite the definitions, many people use the term "Trojan" to refer only to a non-replicating
malicious program.

Then follow procedure describe above. You will find that your machine will shutdown after 1 min.

Note: Implement your own virus

23

You might also like