📄 rijndael.frm
字号:
VERSION 5.00
Begin VB.Form fRijndael
Caption = "Form1"
ClientHeight = 6015
ClientLeft = 60
ClientTop = 345
ClientWidth = 10065
LinkTopic = "Form1"
ScaleHeight = 6015
ScaleWidth = 10065
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdSizeTest
Caption = "Size Test"
Height = 375
Left = 8640
TabIndex = 14
Top = 5520
Visible = 0 'False
Width = 1215
End
Begin VB.CheckBox chkTerminal
Caption = "终端字体"
Height = 255
Left = 2760
TabIndex = 13
Top = 5520
Width = 1815
End
Begin VB.CommandButton cmdFileDecrypt
Caption = "解密文件"
Height = 495
Left = 1320
TabIndex = 12
Top = 5280
Width = 1095
End
Begin VB.CommandButton cmdFileEncrypt
Caption = "加密文件"
Height = 495
Left = 120
TabIndex = 11
Top = 5280
Width = 1095
End
Begin VB.CheckBox Check1
Caption = "十六进制"
Height = 255
Left = 2760
TabIndex = 10
Top = 5160
Visible = 0 'False
Width = 1815
End
Begin VB.ComboBox cboKeySize
Height = 315
Left = 6360
Style = 2 'Dropdown List
TabIndex = 6
Top = 5520
Width = 1695
End
Begin VB.ComboBox cboBlockSize
Height = 315
Left = 6360
Style = 2 'Dropdown List
TabIndex = 5
Top = 5160
Width = 1695
End
Begin VB.TextBox txtPassword
Height = 285
Left = 6360
TabIndex = 4
Text = "Password Passphrase"
Top = 4800
Width = 3495
End
Begin VB.CommandButton cmdDecrypt
Caption = "解密"
Height = 495
Left = 1320
TabIndex = 3
Top = 4680
Width = 1095
End
Begin VB.CommandButton cmdEncrypt
Caption = "加密"
Height = 495
Left = 120
TabIndex = 2
Top = 4680
Width = 1095
End
Begin VB.Frame Frame1
Caption = "数据区"
Height = 4455
Left = 120
TabIndex = 0
Top = 120
Width = 9735
Begin VB.TextBox Text1
Height = 3855
Left = 240
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 1
Top = 360
Width = 9255
End
End
Begin VB.Label Label3
Caption = "密钥长度:"
Height = 255
Left = 4920
TabIndex = 9
Top = 5520
Width = 1455
End
Begin VB.Label Label2
Caption = "字区大小:"
Height = 255
Left = 4920
TabIndex = 8
Top = 5160
Width = 1455
End
Begin VB.Label Label1
Caption = "密钥:"
Height = 255
Left = 4920
TabIndex = 7
Top = 4800
Width = 1455
End
End
Attribute VB_Name = "fRijndael"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
#Const SUPPORT_LEVEL = 0 'Default=0
'Must be equal to SUPPORT_LEVEL in cRijndael
'An instance of the Class
Private m_Rijndael As New cRijndael
'Used to display what the program is doing in the Form's caption
Public Property Let Status(TheStatus As String)
If Len(TheStatus) = 0 Then
Me.Caption = App.Title
Else
Me.Caption = App.Title & " - " & TheStatus
End If
Me.Refresh
End Property
'Assign TheString to the Text property of TheTextBox if possible. Otherwise give warning.
Private Sub DisplayString(TheTextBox As TextBox, ByVal TheString As String)
If Len(TheString) < 65536 Then
TheTextBox.Text = TheString
Else
MsgBox "Can not assign a String larger than 64k " & vbCrLf & _
"to the Text property of a TextBox control." & vbCrLf & _
"If you need to support Strings longer than 64k," & vbCrLf & _
"you can use a RichTextBox control instead.", vbInformation
End If
End Sub
'Returns a String containing Hex values of data(0 ... n-1) in groups of k
Private Function HexDisplay(data() As Byte, n As Long, k As Long) As String
Dim i As Long
Dim j As Long
Dim c As Long
Dim data2() As Byte
If LBound(data) = 0 Then
ReDim data2(n * 4 - 1 + ((n - 1) \ k) * 4)
j = 0
For i = 0 To n - 1
If i Mod k = 0 Then
If i <> 0 Then
data2(j) = 32
data2(j + 2) = 32
j = j + 4
End If
End If
c = data(i) \ 16&
If c < 10 Then
data2(j) = c + 48 ' "0"..."9"
Else
data2(j) = c + 55 ' "A"..."F"
End If
c = data(i) And 15&
If c < 10 Then
data2(j + 2) = c + 48 ' "0"..."9"
Else
data2(j + 2) = c + 55 ' "A"..."F"
End If
j = j + 4
Next i
Debug.Assert j = UBound(data2) + 1
HexDisplay = data2
End If
End Function
'Reverse of HexDisplay. Given a String containing Hex values, convert to byte array data()
'Returns number of bytes n in data(0 ... n-1)
Private Function HexDisplayRev(TheString As String, data() As Byte) As Long
Dim i As Long
Dim j As Long
Dim c As Long
Dim d As Long
Dim n As Long
Dim data2() As Byte
n = 2 * Len(TheString)
data2 = TheString
ReDim data(n \ 4 - 1)
d = 0
i = 0
j = 0
Do While j < n
c = data2(j)
Select Case c
Case 48 To 57 '"0" ... "9"
If d = 0 Then 'high
d = c
Else 'low
data(i) = (c - 48) Or ((d - 48) * 16&)
i = i + 1
d = 0
End If
Case 65 To 70 '"A" ... "F"
If d = 0 Then 'high
d = c - 7
Else 'low
data(i) = (c - 55) Or ((d - 48) * 16&)
i = i + 1
d = 0
End If
Case 97 To 102 '"a" ... "f"
If d = 0 Then 'high
d = c - 39
Else 'low
data(i) = (c - 87) Or ((d - 48) * 16&)
i = i + 1
d = 0
End If
End Select
j = j + 2
Loop
n = i
If n = 0 Then
Erase data
Else
ReDim Preserve data(n - 1)
End If
HexDisplayRev = n
End Function
'Returns a byte array containing the password in the txtPassword TextBox control.
'If "Plaintext is hex" is checked, and the TextBox contains a Hex value the correct
'length for the current KeySize, the Hex value is used. Otherwise, ASCII values
'of the txtPassword characters are used.
Private Function GetPassword() As Byte()
Dim data() As Byte
If Check1.Value = 0 Then
data = StrConv(txtPassword.Text, vbFromUnicode)
ReDim Preserve data(31)
Else
If HexDisplayRev(txtPassword.Text, data) <> (cboKeySize.ItemData(cboKeySize.ListIndex) \ 8) Then
data = StrConv(txtPassword.Text, vbFromUnicode)
ReDim Preserve data(31)
End If
End If
GetPassword = data
End Function
Private Sub cmdEncrypt_Click()
Dim pass() As Byte
Dim plaintext() As Byte
Dim ciphertext() As Byte
Dim KeyBits As Long
Dim BlockBits As Long
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -