Diffie Hellmann Key exchange Protocol code in visual basic.
step 1: Design the form1 and form2
step 2: paste the code and run the application.
Form1.frm
Private
Sub Command1_Click()
Form1.Hide
MsgBox
("Click the form to Enter values")
Form2.Show
End
Sub
Form2.frm
Dim
a, c, b, q, xa, xb, ya, yb, k1, k2, e, f, g, h, i As Double
Private
Sub Command1_Click()
xa
= Val(Text1.Text)
g
= xa
a
= Val(Text4.Text)
q
= Val(Text3.Text)
ya
= 1
e
= a Mod q
Do
If
(xa Mod 2) <> 0 Then
ya
= (ya * e) Mod q
End
If
xa
= Int(xa / 2)
e
= (e * e) Mod q
Loop
Until xa = 0
Text5.Visible
= True
Text5.Text
= ya
Command2.Visible
= True
End
Sub
Private
Sub Command2_Click()
xb
= Val(Text2.Text)
h
= xb
yb
= 1
f
= a Mod q
Do
If
(xb Mod 2) <> 0 Then
yb
= (yb * f) Mod q
End
If
xb
= Int(xb / 2)
f
= (f * f) Mod q
Loop
Until xb = 0
Text6.Visible
= True
Text6.Text
= yb
Command3.Visible
= True
End
Sub
Private
Sub Command3_Click()
k1
= 1
c
= yb Mod q
Do
If
(g Mod 2) <> 0 Then
k1
= (k1 * c) Mod q
End
If
g
= Int(g / 2)
c
= (c * c) Mod q
Loop
Until g = 0
'k1
= (yb ^ xa) Mod q
k2
= 1
d
= ya Mod q
Do
If
(h Mod 2) <> 0 Then
k2
= (k2 * d) Mod q
End
If
h
= Int(h / 2)
d
= (d * d) Mod q
Loop
Until h = 0
'k2
= (ya ^ xb) Mod q
If
k1 = k2 Then
MsgBox
("K1 = " & k1 & vbCrLf & "K2 = " & k2)
Text7.Visible
= True
Text7.Text
= k1
Else
End
End
If
Command5.Visible
= True
End
Sub
Private
Sub Command4_Click()
End
End
Sub
Private
Sub Command5_Click()
Form2.Hide
Form1.Show
Text1.Text
= " "
Text2.Text
= " "
Text3.Text
= " "
Text4.Text
= " "
Text5.Text
= " "
Text6.Text
= " "
Text7.Text
= " "
Text1.Visible
= False
Text2.Visible
= False
Text3.Visible
= False
Text4.Visible
= False
Text5.Visible
= False
Text6.Visible
= False
Text7.Visible
= False
Command1.Visible
= False
Command2.Visible
= False
Command3.Visible
= False
Command5.Visible
= False
End
Sub
Private
Sub Form_Click()
Text1.Visible
= True
Text2.Visible
= True
Text3.Visible
= True
Text4.Visible
= True
Command1.Visible
= True
End
Sub
Private
Sub Form_Load()
Text1.Visible
= False
Text2.Visible
= False
Text3.Visible
= False
Text4.Visible
= False
Text5.Visible
= False
Text6.Visible
= False
Text7.Visible
= False
Command1.Visible
= False
Command2.Visible
= False
Command3.Visible
= False
Command5.Visible
= False
End
Sub
No comments:
Post a Comment