# I am working on cryptography project i have try to generate a public key and private

• 03-17-2007, 11:29 AM
mannuvashishta
I am working on cryptography project i have try to generate a public key and private
Hi
Myself Manu, Currently i am working on cryptography project. I need your help to generate a public and private keys using the RSA algorithm. I have copy my code here can you correct this code and send back to me on my email address mannuvashishta@hotmail.com.
Thank you very much
Manu Vashishta

Programming code to generate public key as well as private key.

Dim GLOINTPORT As Integer
Dim bytCommand As Byte() = New Byte() {}
Dim udpClient As New UdpClient
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a1, b1, c2, d1 As Long
Dim A, i As Integer
Dim c, d, t As Byte
Dim b As Char
'Dim objCrypto As SymmCrypto = New SymmCrypto
Dim c1 As String = ""
'Dim sEncrypted As String
'Dim sDecrypted As String
'Dim Key As String
'Dim sInput As String = TextBox1.Text
'Key = "1234567"

' objCrypto.SymmCrypto(SymmCrypto.SymmProvEnum.DES)
' sEncrypted = objCrypto.Encrypting(sInput, Key)
' MessageBox.Show("Input Value = " + sInput)
'MessageBox.Show("Encrypted Value = " + sEncrypted)

If TextBox1.Text <> "" Then
For A = 1 To TextBox1.TextLength - 1
b = TextBox1.Text.Chars(A)
c1 += Chr(Asc(b) Or (128))
d = "&Hc" ' value to convert and print into binary
'TextBox1.Text = ""
For i = 1 To 8
t = d And c '
If t = &H0 Then ' check if t has zeros only
Debug.Write("0")
TextBox1.Text = TextBox1.Text + "0"
Else
TextBox1.Text = TextBox1.Text + "1"
Debug.Write("1")
End If
c = c >> 1 ' shift C to the right one bit
Next
'RSA()
TextBox2.Text = c1
Next A
End If
'Generate a key pair using RSA algoritm
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End
End Sub
Function RSA() As Double
Dim a1, b1, c2, d1, e, z, p, phi, q As Long
Dim A, i, n As Integer
Dim c, d, t As Byte
Dim b As Char
Dim PK As Object
Dim M As Object
Dim IsPrime As Boolean

'Generate a Public key

a1 = Rnd() * 1000000
b1 = Rnd() * 1000000
While a1 > 0
c2 = Sqrt(a1)
If IsPrime = True Then
Else
IsPrime = False
End If
q = c2
While b1 > 0
d1 = Sqrt(b1)
If IsPrime = True Then
Else
IsPrime = False
End If
p = 1D
p = p - 1
q = q - 1
phi = (p - 1) * (q - 1)
n = p * q
For e = 2 To (phi - 1)
If i = False Then
z = phi Mod e
If z = 0 Then
Else
PK = e
i = True
TextBox3.Text = PK
End If
End If
Next e
Exit Function
End While
End While
' Generate a Private key
e = False
For q = 1 To 100000
If e = False Then
If ((PK * q) Mod phi) = 1 Then
M = q
e = True
TextBox3.Text = M
End If
End If
Next q
End Function

'Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Dim a As String
'
' a = InputBox("Enter The Secret Key", "Mannu Vashishta")
'
' Dim count As Long, status As Integer, strCfr As String
'
' Dim strANSIInput As String
'
' Dim i As Integer
'
' Dim Index As Integer
'
' TDciph321.DESReset()

' ' convert to hex string
'
' For i = 1 To StrLength Step 2
'
' strCfr = strCfr & Chr("&H" & Mid(S, i, 2))
'
' Next
'
' ' convert to an ansi string
'
' strCfr = StrConv(strCfr, vbFromUnicode)
'
' ' decrypt the string
'
' status = TDciph321.DecryptString(strCfr, LenB(strCfr))
'
' ' convert back to Unicode
'
'' strANSIInput = StrConv(strCfr, vbUnicode)
'
' Decrypt = strANSIInput
'
' End Function
' End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim man As NetworkAccess

Dim client As UdpClient
'Dim abc As IPv6MulticastOption
Dim GLOINTPORT As Integer
Dim bytCommand As Byte() = New Byte() {}
Dim pRet As Integer
GLOINTPORT = TextBox2.Text
UdpClient.Connect(GLOIP, GLOINTPORT)
bytCommand = Encoding.ASCII.GetBytes(TextBox2.Text)
pRet = UdpClient.Send(bytCommand, bytCommand.Length)
Console.WriteLine("No messagae send " & pRet)

' Returns True if connection is available
' Replace www.yoursite.com with a site that
' is guaranteed to be online - perhaps your
' corporate site, or microsoft.com
' Dim objUrl As New System.Uri("http://www.hotmail.com/")
' Setup WebRequest
'Dim objWebReq As System.Net.WebRequest
'objWebReq = System.Net.WebRequest.Create(objUrl)
'Dim objResp As System.Net.WebResponse
'Try
' Attempt to get response and return True
'objResp = objWebReq.GetResponse
'objResp.Close()
'objWebReq = Nothing
'Return True
'Catch ex As Exception
' ' Error, exit and return False
' objResp.Close()
' objWebReq = Nothing
' Return False
' End Try

End Sub
End Class
• 04-06-2007, 12:47 PM
quelg