📄 rsa.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 8430
ClientLeft = 60
ClientTop = 450
ClientWidth = 10575
LinkTopic = "Form1"
ScaleHeight = 8430
ScaleWidth = 10575
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame1
Caption = "Frame1"
Height = 4215
Left = 360
TabIndex = 23
Top = 4320
Width = 6615
Begin VB.CommandButton Command9
Caption = "解密"
Height = 495
Left = 4080
TabIndex = 27
Top = 480
Width = 735
End
Begin VB.CommandButton Command8
Caption = "加密"
Height = 495
Left = 960
TabIndex = 26
Top = 480
Width = 735
End
Begin VB.TextBox Text10
Height = 2175
Left = 3480
TabIndex = 25
Text = "Text10"
Top = 1680
Width = 2415
End
Begin VB.TextBox Text9
Height = 2175
Left = 360
TabIndex = 24
Text = "Text9"
Top = 1680
Width = 2175
End
Begin VB.Label Label9
Caption = "密文"
Height = 255
Left = 4200
TabIndex = 29
Top = 1200
Width = 615
End
Begin VB.Label Label8
Caption = "明文"
Height = 255
Left = 1080
TabIndex = 28
Top = 1200
Width = 375
End
End
Begin VB.TextBox Text8
Height = 495
Left = 8640
TabIndex = 22
Text = "Text8"
Top = 2160
Width = 1575
End
Begin VB.TextBox Text5
Height = 495
Left = 5760
TabIndex = 20
Text = "Text5"
Top = 2160
Width = 1455
End
Begin VB.ListBox List1
Height = 2400
Left = 2160
TabIndex = 19
Top = 360
Width = 1095
End
Begin VB.CommandButton Command5
Caption = "恢复"
Height = 495
Left = 9120
TabIndex = 18
Top = 3240
Width = 855
End
Begin VB.CommandButton Command4
Caption = "检验"
Height = 495
Left = 7920
TabIndex = 17
Top = 3240
Width = 975
End
Begin VB.CommandButton Command3
Caption = "计算"
Height = 495
Left = 6600
TabIndex = 16
Top = 3240
Width = 975
End
Begin VB.TextBox Text7
Height = 495
Left = 8640
TabIndex = 15
Text = "Text7"
Top = 1080
Width = 1575
End
Begin VB.TextBox Text6
Height = 495
Left = 8640
TabIndex = 13
Text = "Text6"
Top = 360
Width = 1575
End
Begin VB.OptionButton Option2
Caption = "加密"
Height = 375
Left = 5280
TabIndex = 11
Top = 3360
Width = 855
End
Begin VB.OptionButton Option1
Caption = "数字签名"
Height = 375
Left = 3720
TabIndex = 10
Top = 3360
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "清除"
Height = 495
Left = 2160
TabIndex = 9
Top = 3240
Width = 975
End
Begin VB.TextBox Text4
Height = 615
Left = 5760
TabIndex = 8
Text = "Text4"
Top = 1080
Width = 1455
End
Begin VB.TextBox Text3
Height = 495
Left = 5760
TabIndex = 7
Text = "Text3"
Top = 360
Width = 1455
End
Begin VB.CommandButton Command1
Caption = "计算 "
Height = 495
Left = 480
TabIndex = 3
Top = 3240
Width = 735
End
Begin VB.TextBox Text2
Height = 615
Left = 360
TabIndex = 2
Text = "Text2"
Top = 2160
Width = 1215
End
Begin VB.TextBox Text1
Height = 495
Left = 360
TabIndex = 1
Text = "Text1"
Top = 1320
Width = 1215
End
Begin VB.Label Label7
Caption = "公钥N="
Height = 375
Left = 7560
TabIndex = 21
Top = 2160
Width = 735
End
Begin VB.Label Label6
Caption = "公钥D="
Height = 255
Left = 7680
TabIndex = 14
Top = 1080
Width = 735
End
Begin VB.Label Label5
Caption = "私钥E="
Height = 255
Left = 7560
TabIndex = 12
Top = 360
Width = 735
End
Begin VB.Label Label4
Caption = "f(N)="
Height = 255
Left = 4560
TabIndex = 6
Top = 2160
Width = 615
End
Begin VB.Label Label3
Caption = "Q="
Height = 255
Left = 4680
TabIndex = 5
Top = 1200
Width = 495
End
Begin VB.Label Label2
Caption = "P="
Height = 255
Left = 4680
TabIndex = 4
Top = 360
Width = 495
End
Begin VB.Label Label1
Caption = "计算素数"
Height = 375
Left = 600
TabIndex = 0
Top = 480
Width = 735
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
List1.Clear
a = Val(Text1.Text)
b = Val(Text2.Text)
i = 2
For n = a + 1 To b
s = 0
For i = 2 To Int(Sqr(n))
If n Mod i = 0 Then
s = 1
Exit For
End If
Next
If s = 0 Then List1.AddItem n
Next
End Sub
Private Sub Command2_Click()
List1.Clear
End Sub
Private Sub Command3_Click()
Text7.Visible = True
Text6.Visible = True
a = Val(Text3.Text)
b = Val(Text4.Text)
n = (a - 1) * (b - 1)
m = a * b
Text5.Text = n
Text8.Text = m
Select Case Ture
Case Option1.Value
e = Val(Text6.Text)
d = 1
Do While d < 10000000 And sss = 0
da = d * e
ss = da Mod n
If ss = 1 Then
Text7.Text = d
sss = 1
Else: d = d + 1
End If
Loop
Case Option2.Value
d = Val(Text7.Text)
e = 1
Do While e < 10000000 And sss = 0
da = d * e
ss = da Mod n
If ss = 1 Then
Text6.Text = e
sss = 1
Else: e = e + 1
End If
Loop
End Select
End Sub
Private Sub Command4_Click()
e = Val(Text6.Text)
n = Val(Text5.Text)
m = Val(Text8.Text)
d = Val(Text7.Text)
r = n Mod e
If r = 0 Then
mmad = MsgBox("e值不符合要求,请重新输入e值", 0, "密钥选择")
Else
Text3.Visible = False
Text4.Visible = False
Text5.Visible = False
C = "恭喜您!!!计算成功" & Chr(13)
C = C & "" & Chr(13)
C = C & "=====================================" & Chr(13)
C = C & Format(" 您的公钥E是" & e) & Chr(13)
C = C & Format(" 您的公钥N是" & m) & Chr(13)
C = C & Format(" 您的私钥D是" & d) & Chr(13)
C = C & "=====================================" & Chr(13)
C = C & "" & Chr(13)
C = C & "您可以使用公钥E和N加密消息,也可以用公钥N和私钥" & Chr(13)
C = C & "D签名消息" & Chr(13)
mmm = MsgBox(C, 0, "信息公布")
End If
End Sub
Private Sub Command5_Click()
Text3.Visible = True
Text4.Visible = True
Text5.Visible = True
End Sub
Private Sub Command8_Click()
Dim e, m, i, j, a(), a1, data, r, b(), miwen
data = Val(Text9.Text)
e = Val(Text6.Text)
r = Val(Text8.Text)
i = 1
panduan: m = 2 ^ i
If m > e Then
GoTo change
Else
i = i + 1
GoTo panduan
End If
change: ReDim a(0 To i - 1)
a1 = i - 1
For j = 0 To i - 1
a(j) = 0
Next j
a(i - 1) = 1
huan: i = 1
panduan1: m = 2 ^ i
If m > e Then
GoTo change1
Else
i = i + 1
GoTo panduan1
End If
change1: a(i - 1) = 1
e = e - 2 ^ (i - 1)
If e > 0 Then GoTo huan
For j = 0 To a1
Next j
jiami: ReDim b(0 To a1)
miwen = 1
b(0) = data Mod r
For j = 1 To a1
b(j) = b(j - 1) ^ 2 Mod r
Next j
For j = 0 To a1
miwen = miwen * (b(j) ^ a(j)) Mod r
Next j
Text9.Text = miwen
End Sub
Private Sub Command9_Click()
Dim e, m, i, j, a(), a1, data, r, b(), mingwen
data = Val(Text9.Text)
d = Val(Text7.Text)
r = Val(Text8.Text)
i = 1
panduan: m = 2 ^ i
If m > d Then
GoTo change
Else
i = i + 1
GoTo panduan
End If
change: ReDim a(0 To i - 1)
a1 = i - 1
For j = 0 To i - 1
a(j) = 0
Next j
a(i - 1) = 1
huan: i = 1
panduan1: m = 2 ^ i
If m > d Then
GoTo change1
Else
i = i + 1
GoTo panduan1
End If
change1: a(i - 1) = 1
d = d - 2 ^ (i - 1)
If d > 0 Then GoTo huan
For j = 0 To a1
Next j
jiami: ReDim b(0 To a1)
mingwen = 1
b(0) = data Mod r
For j = 1 To a1
b(j) = b(j - 1) ^ 2 Mod r
Next j
For j = 0 To a1
mingwen = mingwen * (b(j) ^ a(j)) Mod r
Next j
Text10.Text = mingwen
End Sub
Private Sub Option1_Click()
Text6.Visible = False
Text7.Visible = True
End Sub
Private Sub Option2_Click()
Text7.Visible = False
Text6.Visible = True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -