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

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

Copyright 2017 Infinite Loop Ltd.