VERSION 5.00 Begin VB.Form Form1 Caption = "RSA" ClientHeight = 7260 ClientLeft = 165 ClientTop = 555 ClientWidth = 10560 LinkTopic = "Form1" ScaleHeight = 7260 ScaleWidth = 10560 StartUpPosition = 3 'Windows Default Begin VB.PictureBox Picture1 Height = 255 Left = 2160 ScaleHeight = 195 ScaleWidth = 675 TabIndex = 26 Top = 6240 Width = 735 End Begin VB.TextBox Text5 Height = 285 Left = 2160 TabIndex = 24 Text = "5" Top = 5520 Width = 735 End Begin VB.CommandButton Command2 Caption = "Обнулить счетчик" Height = 375 Left = 3120 TabIndex = 22 Top = 6720 Width = 1575 End Begin VB.CommandButton Command1 Caption = "Сгенерировать е" Height = 375 Left = 3120 TabIndex = 21 Top = 6240 Width = 1575 End Begin VB.TextBox Text3 Height = 285 Left = 480 TabIndex = 15 Text = "13" Top = 4320 Width = 975 End Begin VB.PictureBox Picture3 Height = 255 Left = 480 ScaleHeight = 195 ScaleWidth = 915 TabIndex = 14 Top = 6240 Width = 975 End Begin VB.PictureBox Picture2 Height = 255 Left = 480 ScaleHeight = 195 ScaleWidth = 915 TabIndex = 13 Top = 5520 Width = 975 End Begin VB.PictureBox Picture5 Appearance = 0 'Flat BackColor = &H80000005& ForeColor = &H80000008& Height = 2415 Left = 6000 ScaleHeight = 2385 ScaleWidth = 4065 TabIndex = 11 Top = 1440 Width = 4095 End Begin VB.TextBox Text7 Height = 285 Left = 6000 TabIndex = 10 Top = 600 Width = 4215 End Begin VB.TextBox Text6 Height = 285 Left = 240 TabIndex = 9 Top = 600 Width = 4215 End Begin VB.PictureBox Picture4 Appearance = 0 'Flat BackColor = &H80000005& ForeColor = &H80000008& Height = 2415 Left = 240 ScaleHeight = 2385 ScaleWidth = 4185 TabIndex = 8 Top = 1440 Width = 4215 End Begin VB.TextBox Text4 Height = 285 Left = 480 TabIndex = 7 Text = "17" Top = 4800 Width = 975 End Begin VB.CommandButton Combtn5 Caption = "Дешифровать" Height = 375 Left = 4560 TabIndex = 5 Top = 2520 Width = 1335 End Begin VB.CommandButton Combtn4 Caption = "Выходной файл" Height = 375 Left = 7440 TabIndex = 4 Top = 120 Width = 1695 End Begin VB.CommandButton Combtn3 Caption = "Выход" Height = 375 Left = 5400 TabIndex = 3 Top = 6720 Width = 1695 End Begin VB.CommandButton Combtn2 Caption = "Шифровать" Height = 375 Left = 4560 TabIndex = 2 Top = 1920 Width = 1335 End Begin VB.CommandButton Combtn1 Caption = "Входной файл" Height = 375 Left = 1440 TabIndex = 1 Top = 120 Width = 1695 End Begin VB.Label Label9 Caption = "e =" Height = 255 Left = 1800 TabIndex = 25 Top = 6240 Width = 495 End Begin VB.Label Label8 Caption = "d =" Height = 255 Left = 1800 TabIndex = 23 Top = 5520 Width = 495 End Begin VB.Label Label7 Caption = "M =" Height = 255 Left = 120 TabIndex = 20 Top = 6240 Width = 375 End Begin VB.Label Label6 Caption = "N =" Height = 255 Left = 120 TabIndex = 19 Top = 5520 Width = 255 End Begin VB.Label Label5 Caption = "q = " Height = 255 Left = 120 TabIndex = 18 Top = 4800 Width = 255 End Begin VB.Label Label4 Caption = "p =" Height = 255 Left = 120 TabIndex = 17 Top = 4320 Width = 255 End Begin VB.Label Label3 Caption = "Закрытый ключ:" Height = 255 Left = 600 TabIndex = 16 Top = 6000 Width = 1575 End Begin VB.Label Label11 Alignment = 2 'Center Caption = "Открытый ключ:" Height = 255 Left = 480 TabIndex = 12 Top = 5280 Width = 1575 End Begin VB.Label Label2 Caption = "Полученный текст:" Height = 255 Left = 6000 TabIndex = 6 Top = 1080 Width = 1695 End Begin VB.Label Label1 Caption = "Исходный текст:" Height = 255 Left = 240 TabIndex = 0 Top = 1080 Width = 1455 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Public p, q, M, N, x0, x, e, s, s_ As Long Public ch, ost, k, sk As Integer Public stroka, e_bin_str_, e_bin_str As String Public b1, b2 As Byte Private Sub Combtn1_Click() open_type = 1 Form3.Show End Sub Private Sub Combtn2_Click() If (Form1.Text6.Text = "") Or (Form1.Text7.Text = "") Then MsgBox "Для начала имена файлов надо ввести", vbCritical, "косяк!" Exit Sub End If Picture2.Cls Picture3.Cls Picture5.Cls p = Val(Text3.Text) q = Val(Text4.Text) N = p * q M = (p - 1) * (q - 1) d = Val(Text5.Text) Picture2.Print N Picture3.Print M 'это разложение d в двоичную форму: ch = d e_bin_str_ = "" e_bin_str = "" Do ost = ch Mod 2 ch = ch \ 2 e_bin_str_ = e_bin_str_ + Str(ost) Loop Until ch = 1 e_bin_str_ = e_bin_str_ + "1" For k = 1 To Len(e_bin_str_) e_bin_str = e_bin_str + Mid(e_bin_str_, Len(e_bin_str_) - k + 1, 1) Next 'Открываем файлы Open Form1.Text6.Text For Input As #3 Open Form1.Text7.Text For Output As #4 i = 1 Do Input #3, stroka For j = 1 To Len(stroka) s = Asc(Mid(stroka, j, 1)) ' - считываем по одной буковке, берем ее аски 'Picture6.Print s 'используем алгоритм модульного возведения в степень sk = 1 For k = 1 To Len(e_bin_str) If Mid(e_bin_str, k, 1) = "1" Then sk = (sk ^ 2 * s) Mod N End If If Mid(e_bin_str, k, 1) = "0" Then sk = (sk ^ 2) Mod N End If Next s_ = sk 'Picture7.Print s_ stroka_ = stroka_ + Chr(s_) Next Picture5.Print stroka_ Print #4, stroka_ stroka_ = "" Loop Until EOF(3) Close #3 Close #4 End Sub Private Sub Combtn3_Click() End End Sub Private Sub Combtn4_Click() open_type = 2 Form3.Show End Sub Private Sub Combtn5_Click() If (Form1.Text6.Text = "") Or (Form1.Text7.Text = "") Then MsgBox "Для начала имена файлов надо ввести", vbCritical, "косяк!" Exit Sub End If If e = 0 Then MsgBox "Соблаговолите сгенерировать е", vbCritical, "косяк!" Exit Sub End If Picture2.Cls Picture3.Cls Picture5.Cls p = Val(Text3.Text) q = Val(Text4.Text) N = p * q M = (p - 1) * (q - 1) d = Val(Text5.Text) Picture2.Print N Picture3.Print M 'это разложение e в двоичную форму: ch = e e_bin_str_ = "" e_bin_str = "" Do ost = ch Mod 2 ch = ch \ 2 e_bin_str_ = e_bin_str_ + Str$(ost) Loop Until ch = 1 e_bin_str_ = e_bin_str_ + "1" For k = 1 To Len(e_bin_str_) e_bin_str = e_bin_str + Mid(e_bin_str_, Len(e_bin_str_) - k + 1, 1) Next Open Form1.Text6.Text For Input As #3 Open Form1.Text7.Text For Output As #4 i = 1 Do stroka_ = "" Input #3, stroka For j = 1 To Len(stroka) s = Asc(Mid(stroka, j, 1)) sk = 1 For k = 1 To Len(e_bin_str) If Mid(e_bin_str, k, 1) = "1" Then sk = sk ^ 2 * s Mod N End If If Mid(e_bin_str, k, 1) = "0" Then sk = (sk ^ 2) Mod N End If Next s_ = sk stroka_ = stroka_ + Chr(s_) Next Picture5.Print stroka_ Print #4, stroka_ Loop Until EOF(3) Close #3 Close #4 End Sub Private Sub Command1_Click() p = Val(Text3.Text) q = Val(Text4.Text) N = p * q M = (p - 1) * (q - 1) Picture2.Cls Picture3.Cls Picture2.Print N Picture3.Print M d = Val(Text5.Text) x = x0 Do x = x + 1 Loop Until ((M * x + 1) / d) - ((M * x + 1) \ d) = 0 x0 = x e = Int((M * x + 1) \ d) Picture1.Cls Picture1.Print e End Sub Private Sub Command2_Click() x0 = 0 Picture1.Cls End Sub