Experiment: 1 Euclidean and Extended Euclidean Algorithm
Experiment: 1 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; r2b;
while(r2>0)
{
qr1 / r2;
rr1 – q*r2;
r1r2;
r2r;
}
GCD(a,b) r1
}
{
r1 n; r2b;
t10; t2 1;
while(r2>0)
{
qr1 / r2;
rr1 – q*r2;
1
r1r2;
r2r;
tt1 – q*t2;
t1t2;
t2t;
}
if(r1==1)
{
if(t1<0)
{
b-1 t1+ n
}
else
b-1 t1;
}
else
print "Inverse is not Possible”
}
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
Example:
Use the additive cipher with key = 15 to encrypt the message “hello”.
Solution
Use the additive cipher with key = 15 to decrypt the message “WTAAD”.
4
Solution
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).
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
Background
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
Theory:
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:
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:
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.
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.
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.
When Alice constructed her public enciphering key a, she first generated a super-
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.
12
and
Exercise:
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.
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
K= YB XA mod q
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.
15
Experiment : 8
MD-5 algorithm
Aim: To study MD-5 algorithm
16
Implementation details:
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.
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
word A: 01 23 45 67
word B: 89 ab cd ef
word C: fe dc ba 98
word D: 76 54 32 10
Four functions will be defined such that each function takes an input of
three 32-bit words and produces a 32-bit word output.
Round 1.
[abcd k s i] denote the operation a = b + ((a + F (b, c, d) + X [k] + T [i]) <<< s).
18
MD5 vs. MD4
• The shift amounts in each round have been optimized. The shifts in
different rounds are distinct.
19
Experiment : 9
S-DES symmetric encryption
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
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.
23