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

Click the decrypt button, and add the following code:

VB.NET

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

        Dim tok As Double

        Dim ptr As Double

        Dim z As Int16

        Dim decSt As String

        For z = 1 To Len(txtEncrypt.Text)

            ptr = InStr(z, txtEncrypt.Text, "+")

            tok = Val(Mid(txtEncrypt.Text, z, ptr))

            decSt = decSt & Chr(Mult(tok, Key(2), Key(3)))

            z = ptr

        Next z

        txtDecrypt.Text = decSt

 End Sub

C#

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

{

    double tok;

    int ptr;

    int z;

    string decSt = "";

    for (z = 1;z<txtEncrypt.Text.Length;z++)

    {

            ptr = txtEncrypt.Text.IndexOf("+",z);

            tok = Convert.ToDouble(txtEncrypt.Text.Substring(z, ptr-z));

            decSt += (char)Mult(tok, Key[2], Key[3]);

            z = ptr;

    }

    txtDecrypt.Text = decSt;

}

This function splits the encrypted text into numerical values, and passes them to the Mult function, which consists of –

VB.NET

Public Function Mult(ByVal x As Double, ByVal p As Double, ByVal m As _ Double) As Double

        Dim y As Double

        On Error GoTo error1

        y = 1

        Do While p > 0

            Do While (p / 2) = Int(p / 2)

                System.Windows.Forms.Application.DoEvents()

                x = (x * x) Mod m

                p = p / 2

            Loop

            y = (x * y) Mod m

            p = p - 1

        Loop

        Mult = y

        Exit Function

error1:

        y = 0

End Function

C#

public double Mult(double x,double p,double m)

{

    double y;

    y = 1;

    while (p > 0)

    {

            while ((p / 2) == Convert.ToInt64(p / 2))

            {

                    System.Windows.Forms.Application.DoEvents();

                    x = (x * x) % m;

                    p /= 2;

            }

            y = (x * y) % m;

            p--;

    }

    return y;                      

}

This function is used for both encryption and decryption; the difference is simply the value of the parameter ‘p’. If p is the public key, then it decrypts, if it is the public key, then it encrypts.

To test the application, run it from Visual Studio .NET, press ‘generate keys’ then type some text in the ‘text to encrypt’ box, then press ‘encrypt’ then ‘decrypt’.




Google

© 2008 Free SMS| Sage Line 50 Component