Calculate & compare hashes

Discuss and share scripts and script files...
Post Reply
highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Calculate & compare hashes

Post by highend »

I often need to compare file hashes with one / many, posted on the website where the file(s) is / are downloaded from.
To make this efficient I wrote this little script...

When invoked without any hashes in the clipboard, it looks like this:
no clp.png
no clp.png (7.1 KiB) Viewed 2517 times
You can calculate all (md5, sha1, sha256, sha512, crc32/xxh32) checksum(s) for all selected files
or a specific hash (Calculate <hash>) or compare it with a hash (that you need to enter / paste into
the input box after choosing any of these options).


It looks like this, if the clipboard contains any hashes:
clp.png
clp.png (6.5 KiB) Viewed 2517 times
If you have any arbitrary text in the clipboard, e.g. you've copied the whole text from
https://www.xyplorer.com/download/XYHash-19.10.0000.txt
to make sure that your downloaded "xyplorer_full.zip" file has the correct checksum,
the script will scan the clipboard for matching checksums in the order of the value
from the .ini file: Preferred_Hash_Order=md5|sha512|sha256|sha1|crc32
(You are free to adapt that to your requirements!)

A very convenient way to check if the hash for a file is correct...

Btw, there are a lot of options that you can define in the .ini file!

I'm attaching xxhsum.exe as well. You need to modify the .ini after the script was
launched at least once to adapt the path for it (XXH_Sum_32_Exe=) and if you
want to use it at all (Use_XXH_Sum_32=). If you use it, it will replace! the CRC32
hash option... Why that? Because they both generate 8 chars long values and it's
impossible to know if it is crc32 or xxh32.

If you don't know xxh32: https://github.com/Cyan4973/xxHash
It is a very! fast non-cryptographic hash algorithm!

Some values from my PC (2 GB test file from a ram disk, 10 rounds):

Code: Select all

xxh32 vs. md5 = ~5-6x faster
xxh32 vs. sha1 = ~5-6x faster
xxh32 vs. sha256 = ~13x faster
xxh32 vs. sha512 = ~9-10x faster
xxh32 vs. crc32 = ~13x faster
This xxhsum.exe was developed in PureBasic, not in C like the one from the
github link. It operates at exactly the same speed!

E.g.:

Code: Select all

xxhsum.exe "R:\BASH Programming Course.iso"

Code: Select all

BASH Programming Course.iso, 2.086.174.720 bytes

Code: Select all

8f213edd|01070.80 ms|R:\BASH Programming Course.iso
While the C version outputs this:

Code: Select all

    $start = now("msecs");
    $hash = runret("""R:\xxhsum.exe"" -H0 ""R:\BASH Programming Course.iso""");
    status "Hash: " . gettoken($hash, 1, " ") . " | Time: " . now("msecs") - $start . " msecs";

Code: Select all

Hash: 8f213edd | Time: 1094 msecs
Current version:
Calculate & compare hashes v0.1.xys
(9.56 KiB) Downloaded 303 times
xxhsum.zip
(35.86 KiB) Downloaded 259 times
One of my scripts helped you out? Please donate via Paypal

SirSocks
Posts: 4
Joined: 14 Apr 2022 14:24

Re: Calculate & compare hashes

Post by SirSocks »

This is very useful. Thank you! :appl:

GreetingsFromPoland
Posts: 216
Joined: 29 Sep 2022 14:20

Re: Calculate & compare hashes

Post by GreetingsFromPoland »

hi! thank you for the script.

VirusTotal is reporting 2 malicious vendors for the posted EXE :
https://www.virustotal.com/gui/file/77c ... 1606385017

Bkav Pro
W32.AIDetectVM.malware2

CrowdStrike Falcon
Win/malicious_confidence_60% (W)

Post Reply