How to append when calculating MD5?

Get help with using AutoHotkey and its commands and hotkeys
afe
Posts: 618
Joined: 06 Dec 2018, 04:36

How to append when calculating MD5?

31 Mar 2019, 13:37

Hello,

How to append when calculating MD5?




Code: Select all

MD5 := Compute_MD5("AutoHotkey.exe")

msgbox % MD5
return


Compute_MD5(FilePath)
{
    A := 0x67452301
    B := 0xEFCDAB89
    C := 0x98BADCFE
    D := 0x10325476


    T := []
    i := 1

    Loop, 64
    {
        T[i] := Floor(4294967296 * abs(sin(i)))

        ++i
    }


    s := [7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
        , 5,  9, 14, 20, 5,  9, 14, 20, 5,  9, 14, 20, 5,  9, 14, 20,
        , 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
        , 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]


    File := FileOpen(FilePath, "r")

    Length := File.Length
    size := Length * 8


    if ( ( ( size // 512 ) = 0 )
    {
         File.RawRead(msg, Length)

         VarSetCapacity(M, 64)

         i := 0
         Loop, Length
         {
             byte := NumGet(msg, i, "UChar")
             NumPut(byte, M, i, "UChar")

             ++i
         }

         NumPut(128, M, Length, "UChar")


         remainder := Mod(size, 512)
         if ( remainder < 448 )
         {
             i := Length + 1
             Loop, %  56 - Length - 1
             {
                 NumPut(0, M, i, "UChar")

                 ++i
             }

             size &= 0xFFFFFFFFFFFFFFFF
             size := ( ( size & 0xFFFFFFFF ) << 32 ) | ( size & >> 32 )

             i := 0
             Loop, 8
             {
                 byte := NumGet(size, i, "UChar")
                 NumPut(byte, M, 56 + i, "UChar")
             }

             X := []
             i := 1
             Loop, 16
             {
                 VarSetCapacity(X[i], 4)

                 j := 0
                 Loop, 4
                 {
                     byte := NumGet(M, j, "UChar")
                     NumPut(byte, X[i], j, "UChar")

                     ++j
                 }

                ++i
             }

             Compute_Block_MD5(X)
         }
         else
         {
             i := Length + 1
             Loop, % 64 - i
             {
                 NumPut(0, M, i, "UChar")

                 ++i
             }

             X := []
             i := 1
             Loop, 16
             {
                 VarSetCapacity(X[i], 4)

                 j := 0
                 Loop, 4
                 {
                     byte := NumGet(M, j, "UChar")
                     NumPut(byte, X[i], j, "UChar")

                     ++j
                 }

                ++i
             }
             Compute_Block_MD5(X)


             VarSetCapacity(M, 64)

             i := 0
             Loop, 56
             {
                 NumPut(0, M, i, "UChar")

                 ++i
             }

             size &= 0xFFFFFFFFFFFFFFFF
             size := ( ( size & 0xFFFFFFFF ) << 32 ) | ( size & >> 32 )

             i := 0
             Loop, 8
             {
                 byte := NumGet(size, i, "UChar")
                 NumPut(byte, M, 56 + i, "UChar")
             }

             X := []
             i := 1
             Loop, 16
             {
                 VarSetCapacity(X[i], 4)

                 j := 0
                 Loop, 4
                 {
                     byte := NumGet(M, j, "UChar")
                     NumPut(byte, X[i], j, "UChar")

                     ++j
                 }

                ++i
             }
             Compute_Block_MD5(X)
         }
    }
    else
    {



; Appending unfinished above


    A := ( ( A && 0xFF ) << 24 ) | ( ( A && 0xFF00 ) << 8 ) | ( ( A && 0xFF0000 ) >> 8 ) | ( ( A && 0xFF ) >> 24 )
    A := Format("{:X}", A)
    B := Format("{:X}", B)
    C := Format("{:X}", C)
    D := Format("{:X}", D)

    MD5 := A . B . C . D

    return, MD5
}


Compute_Block_MD5(ByRef X)
{
    Global A
    Global B
    Global C
    Global D

    Global T := []
    Global s := []

    AA := A
    BB := B
    CC := C
    DD := D


    i := 0
    Loop, 64
    {
        if ( i < 16 )
        {
            F := ( B & C ) | ( ( !B ) & D )
            k := i + 1
        }
        else
        {
            F := ( B & D ) | ( C & ( !D ) )
            k := mod(5 * i + 1, 16) + 1
        }
        else
        {
            F := B ^ C ^ D
            k := mod(3 * i + 5, 16) + 1
        }
        else
        {
            F := C ^ ( B | ( !D ) )
            k := mod(7 * i, 16) + 1
        }

        F := A + F + X[k] + T[i+1]
        A := D
        D := C
        C := B
        B := B + ( ( F << s[i+1] ) | ( F >> ( 32 - s[i+1] ) )

        ++i
    }

    A += AA
    B += BB
    C += CC
    D += DD

    return
}

Return to “Ask For Help”

Who is online

Users browsing this forum: anonymous_personum, Bing [Bot], Google [Bot] and 29 guests