yab*_*b86 6 excel vba excel-vba
我在vba中总是遇到运行时错误:
Sub rsa()
Dim c1 As Long
Dim c2 As Long
Dim z As Long
Dim e As Long
pt = "xa"
n = 187
e = 7
For i = 1 To Len(pt)
b = Mid$(pt, i, 1)
If b <> " " Then
z = Asc(UCase(b))
'Here is the problem:
c = z ^ e Mod n
Text = Text & c
Else
Text = Text & " "
End If
Next i
Cells(20, 4).Value = Text
End Sub
Run Code Online (Sandbox Code Playgroud)
我得到运行时错误c = z ^ e Mod n.
我尝试了不同的数据类型,但没有解决方案.
Dmi*_*liv 10
A Mod B是等于A - Int(A / B) * B,所以你可以尝试使用c = z ^ e - Int(z ^ e / n) * n代替c = z ^ e Mod n.这个对我有用