rsa算法征求,传入一个数字加密得到一个固定的16位数字

2025-01-03 12:01:58
推荐回答(4个)
回答1:

源码再次修改,可以全面防止“随便输入一个16位都能解密”的情况。请验证:

请下载附件。


回答2:

'根据你的意思,简单1位数字加密。请采纳,谢谢!如有疑问,可以追问。
Function fun1(T As String)
'加密实现方法
Randomize
m1 = Int((16 - 3 + 1) * Rnd + 3)
For i = 1 To 14
m2 = m2 & Int((9 - 1 + 1) * Rnd + 1)
Next
m2 = Format(m1, "00") & m2
Mid(m2, m1, 1) = T
fun1 = m2
End Function
Function fun2(T As String)
'解密实现方法
fun2 = Mid$(T, Val(Mid$(T, 1, 2)), 1)
End Function

Private Sub Command1_Click() '加密
Text2.Text = fun1(Text1.Text)
End Sub

Private Sub Command2_Click() '解密
Text1.Text = fun2(Text2.Text)
End Sub

回答3:

添加text1 text2 combo1 command1 command2
设置combo text属性为text1,list属性为text1,text2
Public Function jm(mw As Integer, ms As String)
Dim a As String
a = "12345678"
Select Case ms
Case "text1"
a = Str(mw) + a
a = a * a
a = Format(a, 0)
jm = Left(a, 16)
Case "text2"
a = Str(mw) + a
a = a * a
a = Format(a, 0)
jm = Right(a, 16)
End Select
End Function
Public Function jiemi(yw As String, ms As String)
Select Case ms
Case "text1"
Select Case yw
Case "152415765279684"
jiemi = 0
Case "1262155136527970"
jiemi = 1
Case "4509068696527970"
jiemi = 2
Case "9755982256527970"
jiemi = 3
Case "1700289581652800"
jiemi = 4
Case "2624980937652800"
jiemi = 5
Case "3749672293652800"
jiemi = 6
Case "5074363649652800"
jiemi = 7
Case "6599055005652800"
jiemi = 8
Case "8323746361652800"
jiemi = 9
End Select
Case "text2"
Select Case yw
Case "152415765279684"
jiemi = 0
Case "2621551365279700"
jiemi = 1
Case "5090686965279700"
jiemi = 2
Case "7559822565279700"
jiemi = 3
Case "0028958165280000"
jiemi = 4
Case "2498093765280000"
jiemi = 5
Case "4967229365280000"
jiemi = 6
Case "7436364965280000"
jiemi = 7
Case "9905500565280000"
jiemi = 8
Case "2374636165280000"
jiemi = 9
End Select
End Select
End Function

Private Sub Command1_Click()
If Text1.Text = "" Then
Else
Text2.Text = jm(Text1.Text, Combo1.Text)
End If
End Sub

Private Sub Command2_Click()
If Text1.Text = "" Then
Else
Text2.Text = jiemi(Text1.Text, Combo1.Text)
End If
End Sub
仅提供思路,举了一个例子,算法较简单

回答4:

RSA算法是固定的。
你用“rsa算法”搜一下,可以搜到相关代码。