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

VB.NET

 Dim p, q, PHI As Double

 Dim Key(3) As Double

C#

 double p,q,PHI;

 double[] Key = new double[3];

Click on cmdKeyGen and enter the following code

VB.NET

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

        Dim D, E1, N As Double

        Const PQ_UP As Short = 9999 'set upper limit of random number

        Const PQ_LW As Short = 3170 'set lower limit of random number

        Const KEY_LOWER_LIMIT As Integer = 10000000 'set for 64bit minimum

        p = 0 : q = 0

        Randomize()

        Do Until D > KEY_LOWER_LIMIT 'makes sure keys are 64bit minimum

            Do Until IsPrime(p) And IsPrime(q)

                p = Int((PQ_UP - PQ_LW + 1) * Rnd() + PQ_LW)

                q = Int((PQ_UP - PQ_LW + 1) * Rnd() + PQ_LW)

            Loop

            N = p * q

            PHI = (p - 1) * (q - 1)

            E1 = GCD(PHI)

            D = Euler(E1, PHI)

        Loop

        Key(1) = E1

        Key(2) = D

        Key(3) = N

        txtP.Text = CStr(p) 'P

        txtQ.Text = CStr(q) 'Q

        txtPhi.Text = CStr(PHI) 'PHI

        txtE.Text = CStr(Key(1)) 'E

        txtD.Text = CStr(Key(2)) 'D

        txtN.Text = CStr(Key(3)) 'N

End Sub

C#

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

{

    double D = 0,E1 = 0,N = 0;

    const short PQ_UP  = 9999; //set upper limit of random number

    const short PQ_LW  = 3170; //set lower limit of random number

    const int KEY_LOWER_LIMIT = 10000000; //set for 64bit minimum

    p = 0; q = 0;

    while (!(D > KEY_LOWER_LIMIT)) //makes sure keys are 64bit minimum

    {

            while (!(IsPrime(p) && IsPrime(q)))

            {

                    p = Convert.ToInt64((PQ_UP - PQ_LW + 1) * _

                            (new Random()).NextDouble() + PQ_LW);

                    q = Convert.ToInt64((PQ_UP - PQ_LW + 1) * _

                            (new Random()).NextDouble() + PQ_LW);

            }

            N = p * q;

            PHI = (p - 1) * (q - 1);

            E1 = GCD(PHI);

            D = Euler(E1, PHI);

    }

    Key[1] = E1;

    Key[2] = D;

    Key[3] = N;

    txtP.Text = p.ToString();

    txtQ.Text = q.ToString();

    txtPhi.Text = PHI.ToString();

    txtE.Text = Key[1].ToString();

    txtD.Text = Key[2].ToString();

    txtN.Text = Key[3].ToString();

}

Page 2   Page 4



Google

Free SMS UK Free SMS Ireland SMS Gratis Norway SMS Gratis Sverige Ilmainen SMS Suomi SMS Gratis Danmark SMS Tasuta Eestisse SMS Nemokamai Lietuva SMS Bezmaksas Latviju Darmowe smsy Polska SMS Zdarma Ceské SMS Zdarma Slovensko SMS Gratis Deutschland SMS Gratis Schweiz SMS Gratis Österreich SMS Gratuit Belgique SMS Gratis Nederland SMS Gratuit France SMS Gratis Espańa SMS Gratis Portugal Free SMS South Africa Free SMS USA SMS Percuma Malaysia Free SMS Hong Kong