📄 frmrijndael.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmRijnDael
BorderStyle = 1 'Fixed Single
Caption = "The RijnDael Block Cipher"
ClientHeight = 5205
ClientLeft = 45
ClientTop = 330
ClientWidth = 6480
ForeColor = &H00000000&
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
Picture = "frmRijnDael.frx":0000
ScaleHeight = 347
ScaleMode = 3 'Pixel
ScaleWidth = 432
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command8
Caption = "..."
Height = 255
Left = 6120
TabIndex = 15
Top = 3960
Width = 255
End
Begin VB.TextBox txtDecrypted
Height = 285
Left = 3600
TabIndex = 14
Top = 3960
Width = 2535
End
Begin VB.CommandButton Command7
Caption = "..."
Height = 255
Left = 6120
TabIndex = 12
Top = 3240
Width = 255
End
Begin VB.TextBox txtEncryptedFile
Height = 285
Left = 3600
TabIndex = 11
Top = 3240
Width = 2535
End
Begin VB.CommandButton Command6
Caption = "..."
Height = 255
Left = 6120
TabIndex = 9
Top = 2520
Width = 255
End
Begin VB.TextBox txtRawFile
Height = 285
Left = 3600
TabIndex = 8
Top = 2520
Width = 2535
End
Begin VB.CommandButton Command5
Caption = "Decrypt File"
Height = 375
Left = 480
TabIndex = 5
Top = 3120
Width = 1215
End
Begin VB.TextBox txtPassword
Height = 285
IMEMode = 3 'DISABLE
Left = 3600
PasswordChar = "*"
TabIndex = 4
Text = "password"
Top = 1800
Visible = 0 'False
Width = 2775
End
Begin VB.CommandButton Command4
Caption = "Encrypt File"
Height = 375
Left = 480
TabIndex = 3
Top = 2400
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "Generate Known Answer Tests (KATS)"
Height = 495
Left = 4560
TabIndex = 1
Top = 120
Width = 1815
End
Begin VB.CommandButton Command1
Caption = "Generate FIPS Test Vectors"
Height = 495
Left = 120
TabIndex = 0
Top = 120
Width = 1455
End
Begin MSComDlg.CommonDialog cdb1
Left = 5400
Top = 120
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Label Label6
BackStyle = 0 'Transparent
Height = 975
Left = 480
TabIndex = 16
Top = 3720
Width = 1215
End
Begin VB.Label Label5
BackStyle = 0 'Transparent
Caption = "Decrypted File"
Height = 255
Left = 4320
TabIndex = 13
Top = 3720
Width = 1935
End
Begin VB.Label Label4
BackStyle = 0 'Transparent
Caption = "Encrypted File"
Height = 255
Left = 4320
TabIndex = 10
Top = 3000
Width = 1575
End
Begin VB.Label Label3
BackStyle = 0 'Transparent
Caption = "File To Be Encrypted"
Height = 255
Left = 4200
TabIndex = 7
Top = 2280
Width = 1575
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "Password"
Height = 255
Left = 4440
TabIndex = 6
Top = 1560
Visible = 0 'False
Width = 1695
End
Begin VB.Label Label1
Appearance = 0 'Flat
BackColor = &H80000005&
BackStyle = 0 'Transparent
Caption = " File Encryption Demonstration"
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 855
Left = 480
TabIndex = 2
Top = 960
Width = 2175
End
End
Attribute VB_Name = "frmRijnDael"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' Most of the code here concerns production of the "known answer tests"
' I have checked the output against the original
' C source code, so I know these tests are correct.
' That isn't to say there aren't bugs elsewhere...
' Please read included ReadMe.rtf file for credits, explanations
' and links.
' - Jonathan Daniel, bigcalm@hotmail.com
#Const TRACE_KAT_MCT = True
Private Sub Command1_Click()
makeFIPSTestVectors App.Path & "\fipstest2.txt"
End Sub
Public Sub makeFIPSTestVectors(FileName As String)
Dim i As Long, KeyLength As Long, r As Long, w As Long
Dim KeyInst As New rijndaelKeyInstance
Dim KeyMateria As String
Dim PT() As Long
Dim CT() As Long
Dim FormatStr As String
Dim FileNumber As Long
#If TRACE_KAT_MCT Then
Debug.Print "Making FIPS test vectors"
#End If
FileNumber = FreeFile
Open FileName For Output As #FileNumber
FPrintF FileNumber, "\n" & "================================\n\n" & "FILENAME: '%s'\n\n" & "FIPS Test Vectors\n", FileName
' /* 128-bit key: 00010103...0e0f: */
KeyLength = 128
ReDim PT(KeyLength / 32)
ReDim CT(KeyLength / 32)
KeyMateria = ""
For i = 0 To (KeyLength / 8) - 1
KeyMateria = KeyMateria & PadHexStr(Hex(i))
Next
FPrintF FileNumber, "\n================================\n\n"
FPrintF FileNumber, "KEYSIZE = 128\n\n"
FPrintF FileNumber, "KEY=%s\n\n", KeyMateria
' /* plaintext is always 00112233...eeff: */
PT(0) = &H112233
PT(1) = &H44556677
PT(2) = &H8899AABB
PT(3) = &HCCDDEEFF
' /* encryption: */
KeyInst.makeKey KeyLength, Encrypt, KeyMateria
KeyInst.CipherInit ECB
FPrintF FileNumber, "Round Subkey Values (Encryptions)\n\n"
For r = 0 To KeyInst.mNr
FPrintF FileNumber, "RK%s=", r
For i = 0 To 3
w = KeyInst.rk((4 * r) + i)
FPrintF FileNumber, "%s", PadHexStr(Hex(w), 8)
Next
FPrintF FileNumber, "\n"
Next
FPrintF FileNumber, "\nIntermediate Ciphertext Values (Encryptions)\n\n"
FPrintF FileNumber, "PT="
For i = 0 To 3
FPrintF FileNumber, "%s", PadHexStr(Hex(PT(i)), 8)
Next
FPrintF FileNumber, "\n"
For r = 1 To KeyInst.mNr
KeyInst.cipherUpdateRounds PT, 4, CT, r
FPrintF FileNumber, "CT%s=", r
For i = 0 To 3
FPrintF FileNumber, "%s", PadHexStr(Hex(CT(i)), 8)
Next
FPrintF FileNumber, "\n"
Next
' /* decryption: */
KeyInst.makeKey KeyLength, Decrypt, KeyMateria
KeyInst.CipherInit ECB
FPrintF FileNumber, "\nRound Subkey Values (Decryption)\n\n"
For r = 0 To KeyInst.mNr
FPrintF FileNumber, "RK%s=", r
For i = 0 To 3
w = KeyInst.rk((4 * r) + i)
FPrintF FileNumber, "%s", PadHexStr(Hex(w), 8)
Next
FPrintF FileNumber, "\n"
Next
FPrintF FileNumber, "\nIntermediate Ciphertext Values (Decryption)\n\n"
FPrintF FileNumber, "CT="
For i = 0 To 3
FPrintF FileNumber, "%s", PadHexStr(Hex(CT(i)), 8)
Next
FPrintF FileNumber, "\n"
For r = 1 To KeyInst.mNr
KeyInst.cipherUpdateRounds CT, 4, PT, r
FPrintF FileNumber, "PT%s=", r
For i = 0 To 3
FPrintF FileNumber, "%s", PadHexStr(Hex(PT(i)), 8)
Next
FPrintF FileNumber, "\n"
Next
' /* 192-bit key: 00010103...1617: */
KeyLength = 192
ReDim PT(KeyLength / 32)
ReDim CT(KeyLength / 32)
KeyMateria = ""
For i = 0 To (KeyLength / 8) - 1
KeyMateria = KeyMateria & PadHexStr(Hex(i))
Next
FPrintF FileNumber, "\n" & "================================\n\n" & "FILENAME: '%s'\n\n" & "FIPS Test Vectors\n", FileName
FPrintF FileNumber, "KEYSIZE = %s\n\n", KeyLength
FPrintF FileNumber, "KEY=%s\n\n", KeyMateria
' /* plaintext is always 00112233...eeff: */
PT(0) = &H112233
PT(1) = &H44556677
PT(2) = &H8899AABB
PT(3) = &HCCDDEEFF
' /* encryption: */
KeyInst.makeKey KeyLength, Encrypt, KeyMateria
KeyInst.CipherInit ECB
FPrintF FileNumber, "Round Subkey Values (Encryptions)\n\n"
For r = 0 To KeyInst.mNr
FPrintF FileNumber, "RK%s=", r
For i = 0 To 3
w = KeyInst.rk((4 * r) + i)
FPrintF FileNumber, "%s", PadHexStr(Hex(w), 8)
Next
FPrintF FileNumber, "\n"
Next
FPrintF FileNumber, "\nIntermediate Ciphertext Values (Encryptions)\n\n"
FPrintF FileNumber, "PT="
For i = 0 To 3
FPrintF FileNumber, "%s", PadHexStr(Hex(PT(i)), 8)
Next
FPrintF FileNumber, "\n"
For r = 1 To KeyInst.mNr
KeyInst.cipherUpdateRounds PT, 4, CT, r
FPrintF FileNumber, "CT%s=", r
For i = 0 To 3
FPrintF FileNumber, "%s", PadHexStr(Hex(CT(i)), 8)
Next
FPrintF FileNumber, "\n"
Next
' /* decryption: */
KeyInst.makeKey KeyLength, Decrypt, KeyMateria
KeyInst.CipherInit ECB
FPrintF FileNumber, "\nRound Subkey Values (Decryption)\n\n"
For r = 0 To KeyInst.mNr
FPrintF FileNumber, "RK%s=", r
For i = 0 To 3
w = KeyInst.rk((4 * r) + i)
FPrintF FileNumber, "%s", PadHexStr(Hex(w), 8)
Next
FPrintF FileNumber, "\n"
Next
FPrintF FileNumber, "\nIntermediate Ciphertext Values (Decryption)\n\n"
FPrintF FileNumber, "CT="
For i = 0 To 3
FPrintF FileNumber, "%s", PadHexStr(Hex(CT(i)), 8)
Next
FPrintF FileNumber, "\n"
For r = 1 To KeyInst.mNr
KeyInst.cipherUpdateRounds CT, 4, PT, r
FPrintF FileNumber, "PT%s=", r
For i = 0 To 3
FPrintF FileNumber, "%s", PadHexStr(Hex(PT(i)), 8)
Next
FPrintF FileNumber, "\n"
Next
' /* 256-bit key: 00010103...1e1f: */
KeyLength = 256
ReDim PT(KeyLength / 32)
ReDim CT(KeyLength / 32)
KeyMateria = ""
For i = 0 To (KeyLength / 8) - 1
KeyMateria = KeyMateria & PadHexStr(Hex(i))
Next
FPrintF FileNumber, "\n================================\n\n"
FPrintF FileNumber, "KEYSIZE = %s\n\n", KeyLength
FPrintF FileNumber, "KEY=%s\n\n", KeyMateria
' /* plaintext is always 00112233...eeff: */
PT(0) = &H112233
PT(1) = &H44556677
PT(2) = &H8899AABB
PT(3) = &HCCDDEEFF
' /* encryption: */
KeyInst.makeKey KeyLength, Encrypt, KeyMateria
KeyInst.CipherInit ECB
FPrintF FileNumber, "Round Subkey Values (Encryptions)\n\n"
For r = 0 To KeyInst.mNr
FPrintF FileNumber, "RK%s=", r
For i = 0 To 3
w = KeyInst.rk((4 * r) + i)
FPrintF FileNumber, "%s", PadHexStr(Hex(w), 8)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -