Вы находитесь на странице: 1из 3

Experiment no 2

Aim: Implementation of Diffe Hellman Key exchange algorithm and DES algorithm

Theory:
Asymmetric Encryption of data requires transfer of cryptographic private key. The most challenging part in this
type of encryption is the transfer of the encryption key from sender to receiver without anyone intercepting this
key in between. This transfer or rather generation on same cryptographic keys at both sides secretively was
made possible by the Diffie-Hellman algorithm.

The Diffie-Hellman algorithm was developed by Whitfield Diffie and Martin Hellman in 1976. This algorithm was
devices not to encrypt the data but to generate same private cryptographic key at both ends so that there is no
need to transfer this key from one communication end to another. Though this algorithm is a bit slow but it is
the sheer power of this algorithm that makes it so popular in encryption key generation.

Diffie-Hellman algorithm:
The Diffie-Hellman algorithm is being used to establish a shared secret that can be used for secret
communications while exchanging data over a public network using the elliptic curve to generate points
and get the secret key using the parameters.
 For the sake of simplicity and practical implementation of the algorithm, we will consider only 4
variables one prime P and G (a primitive root of P) and two private values a and b.
 P and G are both publicly available numbers. Users (say Alice and Bob) pick private values a and b
and they generate a key and exchange it publicly, the opposite person received the key and from
that generates a secret key after which they have the same secret key to encrypt.

Step by Step Explanation

ALICE BOB

Public Keys available = P, G Public Keys available = P, G

Private Key Selected = a Private Key Selected = b

Key generated = Key generated =

Exchange of generated keys takes place

Key received = y key received = x

Generated Secret Key Generated Secret Key

Example
Step 1: Alice and Bob get public numbers n = 11, G = 7

Step 2: Alice selected a private key x = 3 and


Bob selected a private key y = 6

Step 3: Alice and Bob compute public values


Alice: A =(7^3 mod 11) = 2
Bob: B =(7^6 mod 11) = 4

Step 4: Alice and Bob exchange public numbers

Step 5: Alice receives public key A = 2 and


Bob receives public key B = 4

Step 6: Alice and Bob compute symmetric keys


Alice: k1 = B^x mod n = 9
Bob: k2 = A^y mod n = 9
Step 7: 9 is the shared secret.

Program:
g=int(intput(“enter G: ”))
n=int(intput(“enter N: ”))
x=int(intput(“enter X: ”))
y=int(intput(“enter Y: ”))
A=((g**x)*n)
print(“Alice ”,A)
B=((g**y)*n)
print(“Alice ”,B)
k1=((B**x)%n)
print(“value of k1 ”,k1)
k2=((A**y)%n)
print(“value of k2 ”,k2)
Output:

Вам также может понравиться