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


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

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

  1. #1
    Join Date
    Mar 2007
    Posts
    1

    Arrow 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 GLOIP As IPAddress
    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))
    c = "&Hc1" ' start with 1000 0000
    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
    GLOIP = IPAddress.Parse(TextBox2.Text)
    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

  2. #2
    Join Date
    Apr 2007
    Posts
    1

    Ensure your numbers are random

    For cryptography you want to make sure the random number generator generates good random numbers, otherwise someone can guess your private key. Check out http://noesis.net.au/resources/prngs/prng.html about poor random numbers in VB by default. You should use a better function than rnd()

Similar Threads

  1. Replies: 0
    Last Post: 09-21-2006, 08:19 AM
  2. Screen Capture Bug
    By Ranger in forum VB Classic
    Replies: 3
    Last Post: 05-29-2006, 09:43 PM
  3. Replies: 3
    Last Post: 04-21-2006, 03:46 PM
  4. Writing in HKEY_LOCAL_MACHINE...Access is denied
    By Martin in forum VB Classic
    Replies: 22
    Last Post: 12-03-2001, 03:53 AM
  5. Screen Capture Bug
    By Ranger in forum VB Classic
    Replies: 0
    Last Post: 12-09-2000, 12:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center