⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmain.frm

📁 a Tiger Hash algorithmn code
💻 FRM
📖 第 1 页 / 共 2 页
字号:
      Top             =   1320
      Width           =   2085
   End
   Begin VB.Label lblTitle 
      BackStyle       =   0  'Transparent
      Caption         =   "Select hash algorithm"
      Height          =   195
      Index           =   3
      Left            =   5580
      TabIndex        =   6
      Top             =   1965
      Width           =   2085
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' ***************************************************************************
' Project:       Test Tiger hash routines
'
' ===========================================================================
'    DATE      NAME / eMAIL
'              DESCRIPTION
' -----------  --------------------------------------------------------------
' 19-Feb-2008  Kenneth Ives  kenaso@tx.rr.com
' ***************************************************************************
Option Explicit

' ***************************************************************************
' Constants
' ***************************************************************************
  Private Const MODULE_NAME As String = "frmMain"
  Private Const TEST_FILE4  As String = "BigFile.dat"   ' test for large amounts of data
  Private Const MB_1        As Long = 1000000           ' 1,000,000
  
' ***************************************************************************
' Module variables
' ***************************************************************************
  Private mintAlgorithm        As Integer
  Private mintExpectedResults  As Integer

Private Sub cboHashType_Click()

    mintAlgorithm = cboHashType.ListIndex  ' capture hash algorithm desired
    
    Select Case mintAlgorithm
           Case 3 To 6
                lblFormTitle.Caption = "Tiger3 Hash Demo"
                lblTitle(0).Caption = cboHashType.Text & "  ** Unofficial **"
           Case Else
                lblFormTitle.Caption = "Tiger2 Hash Demo"
                lblTitle(0).Caption = cboHashType.Text
    End Select
    
    txtOutput.Text = ""   ' empty actual output data textbox
    cboInput_Click
  
End Sub

Private Sub cboInput_Click()
  
    Dim strTestData   As String
    Dim strDataLength As String
    Dim strOutput     As String
    
    On Error GoTo cboInput_Click_Error

    mintExpectedResults = cboInput.ListIndex  ' capture test data desired
    txtInput.Text = ""                        ' empty input textbox
    txtExpected.Text = ""                     ' empty expected output textbox
    txtOutput.Text = ""                       ' empty actual output textbox
    lblTitle(7).Caption = ""                  ' empty test data size display
    
    ' Safety during initial application load
    If mintExpectedResults < 0 Then
        Exit Sub
    End If
        
    SelectResults mintAlgorithm, mintExpectedResults, strTestData, strDataLength, strOutput
    
    ' load input data, input data length, and expected output data to the screen
    txtInput.Text = strTestData
    lblTitle(4).Caption = "Expected output"
    lblTitle(7).Caption = "Input data length:  " & Format$(strDataLength, "#,##0")
    txtExpected.Text = strOutput
    
cboInput_Click_CleanUp:
    On Error GoTo 0
    Exit Sub

cboInput_Click_Error:
    ErrorMsg MODULE_NAME, "cboInput_Click", Err.Description
    Resume cboInput_Click_CleanUp
    
End Sub

Private Sub cboPasses_Click()
    
    glngPasses = Val(Trim$(Left$(cboPasses.Text, 2)))
    cboInput_Click
    
End Sub

Private Sub cmdChoice_Click(Index As Integer)

    Dim lngIndex    As Long
    Dim lngLoop     As Long
    Dim hFile       As Long
    Dim lngPosition As Long
    Dim abytData()  As Byte
    Dim strSource   As String
    Dim strRecord   As String
    
    Erase abytData()  ' Always start with an empty array
    
    Select Case Index
           
           Case 0 ' Start processing
                Screen.MousePointer = vbHourglass
                gblnStopProcessing = False
                cboInput_Click
                
                ' Format form controls
                cboInput.Enabled = False
                cboPasses.Enabled = False
                cboHashType.Enabled = False
                cmdChoice(0).Enabled = False
                cmdChoice(0).Visible = False
                cmdChoice(1).Enabled = True
                cmdChoice(1).Visible = True
                lblTime(0).Caption = Format$(Now(), "hh:nn:ss ampm")
                lblTime(1).Caption = ""
                txtOutput.Text = ""              ' clear the output text box
                
                glngHashMethod = mintAlgorithm   ' save selected hash method
                glngReturnFormat = HASH_RET_HEX  ' save hashed return format
                
                Select Case mintExpectedResults
                
                       Case 0 To 3  ' various test strings
                            ' Convert string data to byte array
                            abytData() = StrConv(Trim$(txtInput.Text), vbFromUnicode)
                            
                            ' Perform hash string function
                            txtOutput.Text = HashString(abytData())
                       
                       Case 4   ' Excert from President Abraham Lincoln
                            ' format the path\filename to be hashed
                            strSource = App.Path & "\" & TEST_FILE1
                            
                            ' Convert path\filename string to byte array
                            abytData() = StrConv(strSource, vbFromUnicode)
                            
                            ' Perform hash file function.  This function
                            ' will open the file and load its contents into
                            ' another byte array and call the HashString
                            ' function.
                            txtOutput.Text = HashFile(abytData())

                       Case 5   ' Binary test file
                            ' format the path\filename to be hashed
                            strSource = App.Path & "\" & TEST_FILE2

                            ' Convert path\filename string to byte array
                            abytData() = StrConv(strSource, vbFromUnicode)
                            
                            ' Perform hash file function.  This function
                            ' will open the file and load its contents into
                            ' another byte array and call the HashString
                            ' function.
                            txtOutput.Text = HashFile(abytData())

                       Case 6   ' Binary test file
                            ' format the path\filename to be hashed
                            strSource = App.Path & "\" & TEST_FILE3

                            ' Convert path\filename string to byte array
                            abytData() = StrConv(strSource, vbFromUnicode)
                            
                            ' Perform hash file function.  This function
                            ' will open the file and load its contents into
                            ' another byte array and call the HashString
                            ' function.
                            txtOutput.Text = HashFile(abytData())

                       Case 7   ' 1,000,000 repetitions of the letter 'a'
                            
                            ' format the path\filename to be hashed
                            DoEvents
                            strSource = App.Path & "\" & TEST_FILE4
                            txtOutput.Text = "Creating test file with 1,000,000 letter a's"
                            
                            ' Make sure the test file is empty
                            hFile = FreeFile
                            Open strSource For Output As #hFile
                            Close #hFile
                            
                            ' Adjust array to exact size
                            ReDim abytData(MB_1 - 1)
                            
                            ' Build an array of data
                            For lngIndex = 0 To MB_1 - 1
                                abytData(lngIndex) = &H61  ' Letter "a" in hex
                            Next lngIndex
                                            
                            ' Load the test file
                            hFile = FreeFile
                            Open strSource For Binary Access Write As #hFile
                            Put #hFile, , abytData()
                            
                            Close #hFile       ' Close test file
                            Erase abytData()   ' Empty array
                            
                            ' Convert path\filename string to byte array
                            DoEvents
                            abytData() = StrConv(strSource, vbFromUnicode)
                            txtOutput.Text = "Generating a hash value."
                            
                            ' Perform hash file function.  This function
                            ' will open the file and load its contents into
                            ' another byte array and call the HashString
                            ' function.
                            txtOutput.Text = HashFile(abytData())
                
                            ' Empty the test file.  No longer needed.
                            hFile = FreeFile
                            Open strSource For Output As #hFile
                            Close #hFile
                End Select
                
                ' Display finish time
                lblTime(1).Caption = Format$(Now(), "hh:nn:ss ampm")
                
                ' Test the results
                If StrComp(txtExpected.Text, txtOutput.Text, vbBinaryCompare) <> 0 Then
                    If gblnStopProcessing Then
                        InfoMsg "User cancelled the processing."
                    Else
                        InfoMsg "Expected results do not match the Actual results." & _
                                 vbCrLf & "Did you make any changes to the code?"
                    End If
                End If
                       
                Erase abytData()
                
                ' Format form controls
                cboInput.Enabled = True
                cboPasses.Enabled = True
                cboHashType.Enabled = True
                cmdChoice(0).Enabled = True
                cmdChoice(0).Visible = True
                cmdChoice(1).Enabled = False
                cmdChoice(1).Visible = False
                Screen.MousePointer = vbNormal
                
           Case 1    ' Stop processing
                gblnStopProcessing = True
                Erase abytData()
                
                ' Format form controls
                lblTime(0).Caption = ""
                lblTime(1).Caption = ""
                cboInput.Enabled = True
                cboPasses.Enabled = True
                cboHashType.Enabled = True
                cmdChoice(0).Enabled = True
                cmdChoice(0).Visible = True
                cmdChoice(1).Enabled = False
                cmdChoice(1).Visible = False
                
                txtOutput.Text = ""                  ' clear the output text box
                Screen.MousePointer = vbNormal
           
           Case 2 ' terminate application
                gblnStopProcessing = True
                Screen.MousePointer = vbNormal
                TerminateProgram
    End Select
    
End Sub

Private Sub Form_Load()
  
    Dim strMsg As String
    
    gblnStopProcessing = False
    strMsg = "Be patient.  The more data to hash the longer it will take.  "
    strMsg = strMsg & "1,000,000 letter a's will take a few minutes."
    
    With frmMain
         
         .Caption = gstrVersion
         .lblFormTitle.Caption = "Tiger2 Hash Demo"
         .txtInput.BackColor = &HB0D7D5
         .txtInput.Text = ""
         .txtExpected.BackColor = &HB0D7D5
         .txtExpected.Text = ""
         .txtOutput.Text = ""
         .lblTime(0).Caption = ""
         .lblTime(1).Caption = ""
         .lblTitle(2).Caption = strMsg
         
         .cboInput.Enabled = True
         .cboPasses.Enabled = True
         .cboHashType.Enabled = True
         .cmdChoice(0).Enabled = True
         .cmdChoice(0).Visible = True
         .cmdChoice(1).Enabled = False
         .cmdChoice(1).Visible = False
         
         ' load combo box
         With .cboHashType
              .Clear
              .AddItem "Tiger-128 (64-bit)"
              .AddItem "Tiger-160 (64-bit)"
              .AddItem "Tiger-192 (64-bit)"
              .AddItem "Tiger-224 (64-bit)"
              .AddItem "Tiger-256 (64-bit)"
              .AddItem "Tiger-384 (64-bit)"
              .AddItem "Tiger-512 (64-bit)"
              .ListIndex = 0
         End With
                 
         With cboPasses
              .Clear
              .AddItem " 3 Iterations"
              .AddItem " 6 Iterations"
              .AddItem " 9 Iterations"
              .AddItem "12 Iterations"
              .AddItem "15 Iterations"
              .ListIndex = 0
         End With
         
         With .cboInput
              .Clear
              .AddItem "abc"
              .AddItem "Alphabet"
              .AddItem "56 Chars"
              .AddItem "112 Chars"
              .AddItem "1515 Text file"
              .AddItem "2175 Binary file"
              .AddItem "12,271 Binary file"
              .AddItem "1,000,000 letter a's"
              .ListIndex = 0
         End With
         
         cboPasses_Click
         
         .Move (Screen.Width - .Width) \ 2, (Screen.Height - .Height) \ 2
         .Show vbModeless
         .Refresh
         
    End With

End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    
    Screen.MousePointer = vbNormal

    If FileExists(App.Path & "\" & TEST_FILE4) Then
        Kill App.Path & "\" & TEST_FILE4
    End If
    
    If UnloadMode = 0 Then
        TerminateProgram
    End If
    
End Sub

Private Sub lblAuthor_Click()
    SendEmail
End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -