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

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