visual basic, vb, active server pages, asp, DHTML, vbscript,java, javscript, c, c++, c__ , source, code, sample, samples, program, programs, routine, routines, source code, snippet, snippets, control, controls, class, classes, module

You are in:
 
The Basics
Visual Basic Home
Categories
Search
Submissions

Advanced
Newest Code
Top Code of Month
Top Code of All Time
Code of the Day
Coding Contest

Beyond the Code
Discuss
Tutorials
Recommend-
ed Reading

Customize

Miscellaneous
Site Home
Other Sites

Latest Code Ticker for Visual Basic
Click here to see a screenshot of this code! GetAllWindowsHwnd's(+childs), Put then in table
By M.C on 5/22

(Screen Shot)

Create Eye-Friendly Menus Using MouseOver
By Sparq on 5/22


Create Eye-Friendly Menus Using MouseOver
By Sparq on 5/22


Click here to see a screenshot of this code! DecHex Color Codes
By eboy on 5/22

(Screen Shot)

Click here to see a screenshot of this code! Display Current Mouse Pointer Image
By Will Brendel on 5/22

(Screen Shot)

Click here to see a screenshot of this code! Alarm Clock
By EXoDuS on 5/21

(Screen Shot)

MS Office Bar Code Macros for Excel and Access
By Brant Anderson on 5/21


Bar Code Check Digit Calculator & Printing Application
By Brant Anderson on 5/21


Mouse over
By Stewart MacFarlane on 5/21


A+ Screen Zoom
By Rocky Clark (Kath-Rock Software) on 5/21


Click here to see a screenshot of this code! Using Option Buttons in a Array
By Adam Spicer on 5/21

(Screen Shot)

FourSevens
By Glen A Jorgensen on 5/21


RANDOM CIRCLE GENERATOR
By Richard Banks on 5/21


Click here to see a screenshot of this code! JK Manager
By Denis Wiegand on 5/21

(Screen Shot)

Simple Update Checker
By Andrew on 5/21


Click here to see a screenshot of this code! Snap
By ZerO Invasion on 5/21

(Screen Shot)

Click here to see a screenshot of this code! MouseMove
By Alexandre Joly on 5/21

(Screen Shot)

Number 2 Letter - algorithm
By Max Christian Pohle on 5/21


File Explorer
By EXoDuS on 5/21


Click here to see a screenshot of this code! Dude Chat
By Travis Ruiz on 5/21

(Screen Shot)

Calculate Angles from the coords of three points
By Kevin Laity on 5/21


Julian Date Converter
By Data Management Systems on 5/21


Screen Manager
By Albert Nicholas Tedja on 5/21


Click here to see a screenshot of this code! Checkers AI
By Viper on 5/21

(Screen Shot)

enter
By Adam Short on 5/21


API Demo V2
By Andy McCurtin on 5/21


mCodE
By amaru on 5/21


MaxiClipper
By ZaMaX23 on 5/21


File Wiping
By Adam on 5/21


Click here to see a screenshot of this code! ActiveX - Scroll Text on Form with Kinjal's Text Scroll ActiveX Control
By Kinjal Patel on 5/20

(Screen Shot)

Click here to put this ticker on your site!


Click here to join the
'Code of the Day' Mailing List


@Backup.com


SQL Server Magazine

Visual Basic Stats

Code: 585,335 lines
Users: 321 online
 
Search for: 
in language:
 
 
Sponsored by:
Help Maker Plus: Windows Help Authoring Tool
 



   

Fast 64bit RSA Encryption Algorithm\

winzip icon
Submitted on: 3/22/2000
By: William Gerard Griffiths

Level: Advanced
User Rating: By 2 Users
Compatibility:VB 5.0/6.0, VB 4.0/32

Users have accessed this code 839 times.
 
 
     The famous rsa public key encryption algorithm, this code is based on the original design by: Asgeir Bjarni Ingvarsson. Now includes source code and zip file with working example.
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

			
'**************************************
'Windows API/Global Declarations for :Fa
'     st 64bit RSA Encryption Algorithm
'**************************************
Public key(1 To 3) As Double
Public p As Double, q As Double
Public PHI As Double


Public Sub keyGen()

    'Generates the keys for E, D and N
    Dim E#, D#, N#
    Const PQ_UP As Integer = 9999 'set upper limit of random number
    Const PQ_LW As Integer = 3170 'set lower limit of random number
    Const KEY_LOWER_LIMIT As Long = 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) ' make sure q and q are primes
            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)
        E = GCD(PHI)
        D = Euler(E, PHI)
    Loop

    key(1) = E
    key(2) = D
    key(3) = N
    
End Sub



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

    'genetates D from (E and PHI) using the 
    '     Euler algorithm
    On Error Resume Next
    Dim u1#, u2#, u3#, v1#, v2#, v3#, q#
    Dim t1#, t2#, t3#, z#, uu#, vv#, inverse#
    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



Private Function GCD(nPHI As Double) As Double

    'generates a random number relatively pr
    '     ime to PHI
    On Error Resume Next
    Dim nE#, y#
    Const N_UP = 99999999 'set upper limit of random number For E
    Const N_LW = 10000000 'set lower limit of random number For E
    Randomize
    nE = Int((N_UP - N_LW + 1) * Rnd + N_LW)
    top:
    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

    
    Goto top
End Function



Private Function IsPrime(lngNumber As Double) As Boolean

    'Returns 'True' if lngNumber is a prime
    
    On Error Resume Next
    Dim lngCount#
    Dim lngSqr#
    Dim x#
    lngSqr = Int(Sqr(lngNumber)) ' Get the int square root


    If lngNumber < 2 Then
        IsPrime = False
        Exit Function
    End If

    lngCount = 2
    IsPrime = True


    If lngNumber Mod lngCount = 0 Then
        IsPrime = False
        Exit Function
    End If

    lngCount = 3


    For x = lngCount To lngSqr Step 2


        If lngNumber Mod x = 0 Then
            IsPrime = False
            Exit Function
        End If

    Next

End Function



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

    'encrypts, decrypts values passed to the


'     function.. e.g.

    'Mult = M^E mod N (encrypt) where M = x 
    '     , E = p, N = m
    'Mult = M^D mod N (decrypt)
    On Error Goto error1
    
    y = 1
    


    Do While p > 0


        Do While (p / 2) = Int((p / 2))
            x = nMod((x * x), m)
            p = p / 2
        Loop

        y = nMod((x * y), m)
        p = p - 1
    Loop

    Mult = y
    Exit Function
    error1:
    y = 0
End Function



Private Function nMod(x As Double, y As Double) As Double

    'this function replaces the Mod command.
    '     instead of z = x Mod y
    'it is now z = nMod(x,y)
    On Error Resume Next
    Dim z#
    z = x - (Int(x / y) * y)
    nMod = z
End Function



Public Function enc(tIp As String, eE As Double, eN As Double) As String

    'returns the long value of the character
    '     s, chained with a +
    'e.g. 12345678+23456789+ etc..
    '**Taken out encryption algorithm to sim
    '     plify program**
    On Error Resume Next
    Dim encSt As String
    encSt = ""
    e2st = ""
    
    If tIp = "" Then Exit Function


    For i = 1 To Len(tIp)
        encSt = encSt & Mult(CLng(Asc(Mid(tIp, i, 1))), eE, eN) & "+"
    Next i

    '** put your encryption algorithm code h
    '     ere **
    enc = encSt
    
End Function



Public Function dec(tIp As String, dD As Double, dN As Double) As String

    'returns the characters from the long va
    '     lues
    'e.g A = 12345678, B = 23456789 etc..
    '**Taken out decryption algorithm to sim
    '     plify program**
    On Error Resume Next
    Dim decSt As String
    decSt = ""
    '** put your decryption algorithm code h
    '     ere **


    For z = 1 To Len(tIp)
        ptr = InStr(z, tIp, "+")
        tok = Val(Mid(tIp, z, ptr))
        decSt = decSt + Chr(Mult(tok, dD, dN))
        z = ptr
    Next z

    dec = decSt
End Function

winzip icon Download code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by Planet Source Code for viruses, but no prevention program can catch 100% of all viruses.  For your own safety, please re-scan this file using a personal virus checker before using it. Also, NEVER run .exe's that are not accompanied by source code--whether from this site or any other site.

If you don't have a virus scanner, you can get one at many places on the net including: McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs and may compile it into an .exe/.dll/.ocx and distribute it in binary format freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Advanced category)?
(The codewith your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
3/22/2000 8:58:07 PM: phYro
i'd really like to know what you did to 
modify this code??? incase you didn't 
notice it has already been submitted!
Keep the Planet clean! If this comment was disrespectful, please click here.

 
3/23/2000 11:31:39 PM: encipher
The code that I submitted was similar 
to the original RSA encryption by 
Asgeir Bjarni Ingvarsson.
the original 
problem was that Asgeir's code would 
not exceed 40bit modulus for the 
keys,
I re-wrote this code and tidied 
it up and managed to increase the 
modulus of the keys to 64bit

Keep the Planet clean! If this comment was disrespectful, please click here.

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 
 

About the Site  |  Feedback  |  Link to the Site  |  Awards  |  Advertising

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.   By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.