2 sicau taozi sicau_taozi 于 2016.03.19 23:14 提问

VB代码编写RSA加密的问题

布局
图片说明
老是提示被除数为0
图片说明
图片说明
代码
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()
Unload Me
End Sub

1个回答

caozhy
caozhy   Ds   Rxr 2016.03.19 23:24
已采纳

调试下,n是不是为0了。你这个是rsa加密么?看着也不像啊。

sicau_taozi
sicau_taozi e的值在我定义的函数中都还有,在加密这函数中去就是0了
一年多之前 回复
sicau_taozi
sicau_taozi n有值,是e的值没有。。。这个我也不知道,按照rsa的原理来写得。。初学者,老师布置的作业。。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!