sicau_taozi 于 2016.03.19 23:14 提问

VB代码编写RSA加密的问题

Private Function jiami(ByVal mingwen1 As Long, ByRef miwen1 As Long)
miwen1 = (mingwen1 ^ e) Mod n
End Function
Public Function RSA(ByVal p As Long, ByVal q As Long, ByRef n2 As Long, ByRef e2 As Long, ByRef d1 As Long)
Dim n1 As Long
Dim e1 As Long
Dim x As Long
Dim y As Long
n2 = p * q
n1 = (p - 1) * (q - 1)
e1 = Int(Rnd() * n1)

If (e1 > 1) And (e1 < n1) And (n1 Mod e1 <> 0) Then
e2 = e1
MsgBox e2
End If
x = 1
y = -1

For x = 1 To 10000
For y = -1 To -10000 Step -1

If e1 * x + n1 * y = 1 Then

d1 = x

Exit For

End If
Next y
Next x

End Function

Public Sub Command1_Click()
Dim mingwen As Long
Dim miwen As Long
Dim panduan As Boolean
Dim n As Long
Dim e As Long
Dim d As Long
Dim tex3 As Long
s = RSA(Asc(Text1.Text), Asc(Text2.Text), n, e, d)
tex3 = Asc(Text3.Text)
panduan = False
If tex3 >= 65 And tex3 <= 122 Then
panduan = True
End If
s1 = jiami(tex3, miwen)
Text4.Text = miwen
End Sub

Private Sub Command2_Click()
End Sub

1个回答

caozhy      2016.03.19 23:24

sicau_taozi e的值在我定义的函数中都还有，在加密这函数中去就是0了

sicau_taozi n有值，是e的值没有。。。这个我也不知道，按照rsa的原理来写得。。初学者，老师布置的作业。。