请提供份RSA加密算法的VB源码

最好好是有完整源码的

rem Simple RSA Program
rem (c) W.Buchanan
rem Jan 2002

Function check_prime(ByVal val As Long) As Boolean
Dim primes
primes = Array(1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397)
check_prime = False

For i = 0 To 78
If (val = primes(i)) Then
prime = True
End If
Next i
check_prime = prime
End Function

Function decrypt(ByVal c, ByVal n, ByVal d As Long)

Dim i, g, f As Long

On Error GoTo errorhandler

If (d Mod 2 = 0) Then
g = 1
Else
g = c
End If

For i = 1 To d / 2

f = c * c Mod n
g = f * g Mod n
Next i
decrypt = g

Exit Function
errorhandler:
Select Case Err.Number ' Evaluate error number.
Case 6
status.Text = "Calculation overflow, please select smaller values"
Case Else
status.Text = "Calculation error"
End Select

End Function

Function getD(ByVal e As Long, ByVal PHI As Long) As Long
Dim u(3) As Long
Dim v(3) As Long
Dim q, temp1, temp2, temp3 As Long

u(0) = 1
u(1) = 0
u(2) = PHI
v(0) = 0
v(1) = 1
v(2) = e

While (v(2) <> 0)
q = Int(u(2) / v(2))
temp1 = u(0) - q * v(0)
temp2 = u(1) - q * v(1)
temp3 = u(2) - q * v(2)
u(0) = v(0)
u(1) = v(1)
u(2) = v(2)
v(0) = temp1
v(1) = temp2
v(2) = temp3
Wend
If (u(1) < 0) Then
getD = (u(1) + PHI)
Else
getD = u(1)
End If
End Function

Function getE(ByVal PHI As Long) As Long
Dim great, e As Long

great = 0
e = 2

While (great <> 1)
e = e + 1
great = get_common_denom(e, PHI)
Wend
getE = e
End Function

Function get_common_denom(ByVal e As Long, ByVal PHI As Long)
Dim great, temp, a As Long

If (e > PHI) Then
While (e Mod PHI <> 0)
temp = e Mod PHI
e = PHI
PHI = temp
Wend
great = PHI
Else
While (PHI Mod e <> 0)
a = PHI Mod e
PHI = e
e = a
Wend
great = e
End If
get_common_denom = great
End Function

Private Sub show_primes()
status.Text = "1"
no_primes = 1
For i = 2 To 400
prime = True
For j = 2 To (i / 2)
If ((i Mod j) = 0) Then
prime = False
End If
Next j

If (prime = True) Then
no_primes = no_primes + 1
status.Text = status.Text + ", " + Str(i)
End If
Next i
status.Text = status.Text + vbCrLf + "Number of primes found:" + Str(no_primes)
End Sub

Private Sub Command1_Click()
Dim p, q, n, e, PHI, d, m, c As Long

p = Text1.Text
q = Text2.Text
If (check_prime(p) = False) Then
status.Text = "p is not a prime or is too large, please re-enter"
ElseIf (check_prime(q) = False) Then
status.Text = "q is not a prime or is too large, please re-enter"
Else
n = p * q
Text3.Text = n

PHI = (p - 1) * (q - 1)
e = getE((PHI))
d = getD((e), (PHI))
Text4.Text = PHI
Text5.Text = d
Text6.Text = e
m = Text7.Text

c = (m ^ e) Mod n
Text8.Text = c
m = decrypt(c, n, d)
Text9.Text = m
Label12.Caption = "Decrypt key =<" + Str(d) + "," + Str(n) + ">"
Label13.Caption = "Encrypt key =<" + Str(e) + "," + Str(n) + ">"
End If
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Command3_Click()
frmBrowser.Show
End Sub

Private Sub Command4_Click()
Call show_primes
End Sub
温馨提示:内容为网友见解,仅供参考
无其他回答

vb.net中实现rsa加密解密 急!急!
static public byte[] RSADecrypt(byte[] DataToDecrypt, RSAParameters RSAKeyInfo,bool DoOAEPPadding){ try { \/\/Create a new instance of RSACryptoServiceProvider.RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();\/\/Import the RSA Key information. This needs \/\/to include the ...

VB调用JS实现RSA本地加密
使用部件Microsoft script control 1.0 (msscript.ocx)应该可以实现。你参考下VB调用JS计算MD5的方法。Private Sub Command1_Click() Set ScriptControl = ScriptControl1 ScriptControl1.Language = "Jscript" ScriptControl1.Timeout = -1 ScriptControl1.AddCode txtVarHexcase.Text Text...

...请高手指教怎么加密,有那种好的加密算法吗?
RSA对刚才的加密密钥进行加密。最后需要说明的是,当前小于1024位的N已经被证明是不安全的自己使用中不要使用小于1024位的RSA,最好使用2048位的。---一个简单的RSA算法实现JAVA源代码:filename:RSA.java\/** Created on Mar 3, 2005** TODO To change the template for this generated file go to* Window - ...

高分求java的RSA 和IDEA 加密解密算法
http:\/\/zeal.newmenbase.net\/attachment\/sorgentiJava.tar.gz - 源代码包 http:\/\/zeal.newmenbase.net\/attachment\/algoritmoRSA.jar - 编译好的jar包另外关于RSA算法的php实现请参见文章: php下的RSA算法实现关于使用VB实现RSA算法的源代码下载(此程序采用了psc1算法来实现快速的RSA加密): http:\/\/zeal.newmenba...

条码计算方法。
参考资料: :zhsy..\/knowledge\/changshi04.htm 程式码690 123456789X求以下演算法的VB程式 1.自右到左的序列号顺序,校验码的序号为1 2.从序号2开始求出偶数位数字之和① 9+7+5+3+1+9=34 ① 3. ①*3=② 34×3=102 ② 4.从序号3开始求出奇数位数字之和③ 8+6+4+2+0+6=26 ③ 5. ②+③=...

怎么用 GO 实现 RSA 的私钥加密公钥解密
origData, err := RsaDecrypt(data)if err != nil { panic(err)} fmt.Println(string(origData))} \/\/ 公钥和私钥可以从文件中读取 var privateKey = []byte(`---BEGIN RSA PRIVATE KEY--- MIICXQIBAAKBgQDZsfv1qscqYdy4vY+P4e3cAtmvppXQcRvrF1cB4drkv0haU24Y 7m5qYtT52Kr539RdbKKdL...

局域网聊天工具的加密算法
AES http:\/\/hi.baidu.com\/gdr_gedao\/blog\/item\/65db5ca9efc364fd1f17a2e2.html AES加密、解密算法原理和AVR实现 AES是分组密钥,算法输入128位数据,密钥长度也是128位。用Nr表示对一个数据分组加密的轮数(加密轮数与密钥长度的关系如表1所列)。每一轮都需要一个与输入分组具有相同长度的扩展...

企业防泄密系统企业防泄密系统介绍
RSA算法:一种非对称加密算法,提供较高的加密强度,解决了密钥管理问题,安全性高,但加密和解密速度慢,不适用于文件加密。AES算法:一种不可逆加密算法,加密过程中无需密钥,适用于数据加密、身份认证和数据安全传输。合力天下防泄密系统采用256位AES加密算法,确保文件加密无从破解。功能列表包括:用户...

html解码的问题
每个字是由\\xxx\\xxx组成的 178对应的是\\262 197对应的是\\305 187对应的是\\273 202对应的是\\312 本来想根据这个对应关系推出算法的,不过看似有点麻烦。因此,最简单的方法就是把所有ASCII和密文对应关系遍历一遍,组成数据库。然后按照对应的关系组合成汉字解码。具体的程序您自己想吧~ 呵呵 ...

求vb md5加解密
vbNullString, PROV_RSA_FULL, 0) If lRes <> 0 Then ' Create the hash lRes = CryptCreateHash(hCtx, Algorithm, 0, 0, hHash) If lRes <> 0 Then ' Hash the string lRes = CryptHashData(hHash, ByVal Str, Len(Str), 0) If lRes <> 0 Then ' Get the ...

相似回答