Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
Available now!
Buy at Amazon US or
Buy at Amazon UK



Articles

» Windows API reference
» Webcam streaming in VB.NET
» Remoting with firewalls
» RSA from first principles
» Key & MouseLogger in .NET
» Networking Resource Kit for .NET
» Migrating VB6 Winsock to VB.NET
» Migrating C++ sockets to C#
» RFC Reference guide
» COM Reference guide
» WMI Reference guide
» SQL stored procedures
» TCP & UDP port reference
» NET Framework reference
» Ethernet Type codes
» MAC address assignments
» DLL entry point reference
» Boost SQL performance
» Free SMS UK
» Free SMS Ireland
» Free SMS South Africa
» Internet Explorer

Contact us

C#

private double Euler(double E3,double PHI3)

{

    double v3, v1, u2, u1, u3, v2, q;

    double vv, t2, t1, t3, uu, inverse;

    u1 = 1;

    u2 = 0;

    u3 = PHI3;

    v1 = 0;

    v2 = 1;

    v3 = E3;

    while (v3 != 0)

    {

            q = Convert.ToInt64(u3 / v3);

            t1 = u1 - q * v1;

            t2 = u2 - q * v2;

            t3 = u3 - q * v3;

            u1 = v1;

            u2 = v2;

            u3 = v3;

            v1 = t1;

            v2 = t2;

            v3 = t3;

    }

    uu = u1;

    vv = u2;

    if (vv < 0)

    {

            inverse = vv + PHI3;

    }

    else

    {

            inverse = vv;

    }

     return inverse;

}

This function generates the decryption (private) key from the public key and Phi by implementing the mathematical equation

e*d = 1 (mod (p-1)*(q-1))

At this point, you can run the application, and press the ‘Generate keys’ button and see the keys being generated in the textboxes.

The next step is to provide functionality for encryption and decryption

Click on the Encrypt button, and add the following code.

VB.NET

Private Sub cmdEncrypt_Click(ByVal eventSender As System.Object, ByVal _ eventArgs As System.EventArgs) Handles cmdEncrypt.Click

        Dim i As Double

        Dim encSt As String

        For i = 1 To Len(txtPlain.Text)

            encSt = encSt & Mult(CInt(Asc(Mid(txtPlain.Text, i, 1))) _

                    , Key(1), Key(3)) & "+"

        Next i

        txtEncrypt.Text = encSt

End Sub

C#

private void cmdEncrypt_Click(object sender, System.EventArgs e)

{

    int i;

    string encSt = "";

    byte[] encodedBytes =

           System.Text.Encoding.ASCII.GetBytes(txtPlain.Text);

    for (i=0;i<txtPlain.Text.Length;i++)

    {

    encSt += Mult(Convert.ToDouble(encodedBytes[i]), Key[1], Key[3]) + "+";

    }

    txtEncrypt.Text = encSt;

}

This function encrypts every character of the plain text one at a time. It separates the resultant values with a ‘+’ symbol. Note that the Mult function has not yet been implemented.

Page 5   Page 7



Google

Copyright 2017 Infinite Loop Ltd.