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

📄 rijndael.cls

📁 Good security provider by using biometric feature as key. This is the program of server.
💻 CLS
📖 第 1 页 / 共 5 页
字号:
    t1 = (Te4(s(4)) And &HFF&) Xor (Te4(s(9)) And &HFF00&) Xor (Te4(s(14)) And &HFF0000) Xor (Te4(s(3)) And &HFF000000) Xor fkey(k + 1)
    t2 = (Te4(s(8)) And &HFF&) Xor (Te4(s(13)) And &HFF00&) Xor (Te4(s(2)) And &HFF0000) Xor (Te4(s(7)) And &HFF000000) Xor fkey(k + 2)
    t3 = (Te4(s(12)) And &HFF&) Xor (Te4(s(1)) And &HFF00&) Xor (Te4(s(6)) And &HFF0000) Xor (Te4(s(11)) And &HFF000000) Xor fkey(k + 3)
    CopyMemory ciphertext(q + 0), t0, 4&
    CopyMemory ciphertext(q + 4), t1, 4&
    CopyMemory ciphertext(q + 8), t2, 4&
    CopyMemory ciphertext(q + 12), t3, 4&
End Sub

'File encryption.  The ciphertext file will be padded to a multiple of (BlockBits\8) bytes.
'One byte is appended to the ciphertext to indicate the length of the final block.
'FileDecrypt recovers this length field and restores the original plaintext file length.
'PlaintextFileName and CiphertextFileName must be distinct, PlaintextFileName must exist,
'CiphertextFileName must not exist, etc.  Be sure to do file checking before calling this.
Public Function FileEncrypt(PlaintextFileName As String, CiphertextFileName As String) As Long
    Dim FileNum     As Integer
    Dim FileNum2    As Integer
    Dim i           As Long
    Dim m           As Long 'ciphertext file size
    Dim n           As Long 'plaintext file size
    Dim data()      As Byte
    
    Const BlockSize As Long = 16 'bytes
    Const MaxBlocks As Long = MaxFileChunkSize \ BlockSize

    n = FileLen(PlaintextFileName)
    m = (n + BlockSize) And (-BlockSize) 'BlockSize=16 specific
    
    FileNum = FreeFile
    Open PlaintextFileName For Binary Access Read As FileNum
    FileNum2 = FreeFile
    Open CiphertextFileName For Binary Access Write As FileNum2

    'For large files, encrypt in pieces no larger than MaxFileChunkSize
    If m > MaxBlocks * BlockSize Then
            ReDim data(MaxBlocks * BlockSize - 1)
            Do
                Get #FileNum, , data
                For i = 0 To (MaxBlocks - 1) * BlockSize Step BlockSize
                        BlockEncrypt data, data, i, i
                Next i
                Put #FileNum2, , data
                m = m - MaxBlocks * BlockSize
            Loop While m > MaxBlocks * BlockSize
    End If

    'Encrypt the last piece of the file
    ReDim data(m - 1)
    Get #FileNum, , data
    data(m - 1) = n Mod BlockSize
    
    For i = 0 To m - BlockSize Step BlockSize
        BlockEncrypt data, data, i, i
    Next i
    Put FileNum2, , data

    Close FileNum
    Close FileNum2
End Function

Private Sub Class_Initialize()
#If COMPILE_CONSTANTS = 0 Then
    Dim i          As Long
    Dim y          As Byte
    Dim s(7)       As Byte
    Dim ib         As Byte
    Dim ptab(255)  As Byte
    Dim ltab(255)  As Byte

    'use 3 as primitive root to generate power and log tables
    ltab(0) = 0
    ltab(1) = 0
    ltab(3) = 1
    ptab(0) = 1
    ptab(1) = 3
    For i = 2 To 255 'ptab(i) = ptab(i - 1) Xor Xtime(ptab(i - 1))
        If (ptab(i - 1) And &H80) Then
            ptab(i) = ptab(i - 1) Xor ((ptab(i - 1) And 127) * 2) Xor &H1B
        Else
            ptab(i) = ptab(i - 1) Xor (ptab(i - 1) * 2)
        End If
        ltab(ptab(i)) = i
    Next i

    'affine transformation:- each bit is xored with itself shifted one bit
    Te4(0) = &H63636363
    Td4(&H63) = 0
    For i = 1 To 255
        y = ptab(255 - ltab(i)) 'multiplicative inverse
        ib = y
        If ib And &H80 Then ib = (ib And 127) * 2 Or 1 Else ib = ib * 2 'RotateLeftByte
        y = y Xor ib
        If ib And &H80 Then ib = (ib And 127) * 2 Or 1 Else ib = ib * 2
        y = y Xor ib
        If ib And &H80 Then ib = (ib And 127) * 2 Or 1 Else ib = ib * 2
        y = y Xor ib
        If ib And &H80 Then ib = (ib And 127) * 2 Or 1 Else ib = ib * 2
        y = y Xor ib Xor &H63

        s(0) = y
        s(1) = s(0)
        s(2) = s(0)
        s(3) = s(0)
        CopyMemory Te4(i), s(0), 4&

        s(0) = i
        s(1) = s(0)
        s(2) = s(0)
        s(3) = s(0)
        CopyMemory Td4(y), s(0), 4&
    Next i

    y = 1
    For i = 0 To UBound(rco)
        rco(i) = y
        If (y And &H80) Then 'y = Xtime(y)
            y = ((y And 127) * 2) Xor &H1B

⌨️ 快捷键说明

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