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

1.Windows API reference
2.HTML to WML Converter
3.Webcam streaming in VB.NET
4.Remoting with firewalls
5.RSA from first principles
6.Key & MouseLogger in .NET
7.Networking Resource Kit for .NET
8.Automatic Reboot with .NET
9.XAML Schema
10.Migrating VB6 Winsock to VB.NET
11.Migrating C++ sockets to C#
12.RFC Reference guide
13.Lingua - Localization webservice
14.COM Reference guide
15.WMI Reference guide
16.SQL stored procedures
17.TCP & UDP port reference
18..NET Framework reference
19.Ethernet Type codes
20.IP to country webservice
21.MAC address assignments
22.DLL entry point reference
23.WHOIS server list
24. Turing Numbers
25. Boost SQL performance
26. Progress Bar in ASP.NET
27. OleDb WebService
27. 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

© 2008 Free SMS| Sage Line 50 Component