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

Private Function GCD(ByRef nPHI As Double) As Double

        Dim x As Double

        Dim nE, y As Double

        Const N_UP As Integer = 99999999 'set upper limit for E

        Const N_LW As Integer = 10000000 'set lower limit for E

        On Error Resume Next

        Randomize()

        nE = Int((N_UP - N_LW + 1) * Rnd() + N_LW)

        Do

            x = nPHI Mod nE

            y = x Mod nE

            If y <> 0 And IsPrime(nE) Then

                GCD = nE

                Exit Function

            Else

                nE = nE + 1

            End If

        Loop

End Function

C#

private double GCD(double nPHI)

{

     double x;

     double nE,y;

     const int N_UP  = 99999999; //set upper limit for E

     const int N_LW  = 10000000; //set lower limit for E

     nE = Convert.ToInt64((N_UP - N_LW + 1) * _

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

     while(true)

     {

          x = nPHI % nE;

          y = x % nE;

          if (y != 0 && IsPrime(nE))

          {

             return nE;

          }

          else

          {

             nE++;

          }

     }

}

GCD generates a number that is relatively prime to (p-1) * (q – 1). This number must be in the order of 10’s of millions, and be prime.

The last function required to generate the public and private keys is the Euler function

VB.NET

Private Function Euler(ByRef E3 As Double, ByRef PHI3 As Double) As Double

        On Error Resume Next

        Dim v3, v1, u2, u1, u3, v2, q As Double

        Dim vv, z, t2, t1, t3, uu, inverse As Double

        u1 = 1

        u2 = 0

        u3 = PHI3

        v1 = 0

        v2 = 1

        v3 = E3

        Do Until (v3 = 0)

            q = Int(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

            z = 1

        Loop

        uu = u1

        vv = u2

        If (vv < 0) Then

            inverse = vv + PHI3

        Else

            inverse = vv

        End If

        Euler = inverse

    End Function

Page 4   Page 6



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