sicau_taozi 2016-03-19 15:14 采纳率: 100%
浏览 1977
已采纳

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条回答 默认 最新

  • threenewbee 2016-03-19 15:24
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 VB6.0中PICTUREBOX加载本地图片无法显示
    • ¥100 关于游戏app session获取的问题
    • ¥15 MYSQL数据库建表
    • ¥15 爬虫程序爬取TTGChina网站文章代码
    • ¥35 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。
    • ¥15 如何用下图方法在AMESim中搭建离心泵模型
    • ¥15 C#连接服务器,请求时报Ssl/Tsl未能建立安全通道
    • ¥15 xcode15build的c++ dylib在10.15上不兼容
    • ¥15 CPLD如何实现在线逻辑分析
    • ¥15 控制面板卸载无权限!!