Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Hasher - Display MD5 and SHA256 Values

May
373
4
Simple function that will display the file (or files) with both MD5 and SHA256 hash values. This is useful if I am comparing the hashes for downloads to values posted online. Some people use MD5, some SHA256 so having both is nice.

Code:
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Command:  hasher FILEGLOB
:: May 2018
::
:: Library command that shows several hash values with one command
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
hasher {
    setlocal

    GetOpt %*

    if defined OPTION_D set DEBUG=1
    
    :: Disable multiple commands, conditional commands, and piping.  I was having
    :: issues with & in filenames.  It should be reset back to normal with endlocal
    setdos /x-5

    :: Ensure a filename is provided
    iff not defined PARAM_0 then
        gosub Usage
        goto EndProgram
    endiff

    :: Loop through the fileglobs provided on the command line.  Process each one.
    do j = 1 to %PARAM_0
        do i in %[PARAM_%j]
            iff isFile %i then
                DebugPrint "'%i' is a File"
                EchoColor YELLOW %i:
                if not defined OPTION_S echo    MD5:  %@Lower[%@MD5[%@Quote[%i]]]
                if not defined OPTION_M echo SHA256:  %@Lower[%@SHA256[%@Quote[%i]]]
            else
                DebugPrint "'%i' is not a file - skipping"
            endiff
            echo.
        enddo
    enddo

    :EndProgram
    setdos /x+5
    endlocal
    quit


    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Usage - Display Usage Information
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :Usage
        echo Usage: hasher [-d] [-m] [-s] FilenameGlob1 FilenameGlob2
        echo  -d:  Debug Mode
        echo  -m:  MD5 Mode Only
        echo  -s:  SHA256 Mode Only
        echo.
        echo Example:  hasher test.abc test.fg*
        echo           hasher Test*
        echo           hasher -m Test*
    return
}
 
Last edited:
Back
Top