Hash from string, hex or file, HMAC, Salt
Re: Hash from string, hex or file, HMAC, Salt
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Hash from string, hex or file, HMAC, Salt
CRC32 (Cyclic redundancy check)
Implementation
example:
output:
DllCall / WinAPI
example:
output:
Implementation
Code: Select all
CRC32(str)
{
static table := []
loop 256 {
crc := A_Index - 1
loop 8
crc := (crc & 1) ? (crc >> 1) ^ 0xEDB88320 : (crc >> 1)
table[A_Index - 1] := crc
}
crc := ~0
loop, parse, str
crc := table[(crc & 0xFF) ^ Asc(A_LoopField)] ^ (crc >> 8)
return Format("0x{:x}", ~crc)
}
Code: Select all
MsgBox % CRC32("The quick brown fox jumps over the lazy dog")
Code: Select all
0x414fa339
DllCall / WinAPI
Code: Select all
CRC32(str, enc = "UTF-8")
{
l := (enc = "CP1200" || enc = "UTF-16") ? 2 : 1, s := (StrPut(str, enc) - 1) * l
VarSetCapacity(b, s, 0) && StrPut(str, &b, floor(s / l), enc)
CRC32 := DllCall("ntdll.dll\RtlComputeCrc32", "UInt", 0, "Ptr", &b, "UInt", s)
return Format("0x{:x}", CRC32)
}
Code: Select all
MsgBox % CRC32("The quick brown fox jumps over the lazy dog")
Code: Select all
0x414fa339
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Hash from string, hex or file, HMAC, Salt
RSHash (Robert Sedgewick's string hashing algorithm)
Implementation
Code: Select all
RSHash(str)
{
a := 0xF8C9, b := 0x5C6B7, h := 0
loop, parse, str
h := h * a + Asc(A_LoopField), a *= b
return (h & 0x7FFFFFFF)
}
Code: Select all
MsgBox % RSHash("jdfgsdhfsdfsd 6445dsfsd7fg/*/+bfjsdgf%$^") ; <== 2012450421
JSHash (A bitwise hash function written by Justin Sobel)
Implementation
Code: Select all
JSHash(str)
{
h := 0x4E67C6A7
loop, parse, str
h ^= ((h << 5) + Asc(A_LoopField) + (h >> 2))
return (h & 0x7FFFFFFF)
}
Code: Select all
MsgBox % JSHash("jdfgsdhfsdfsd 6445dsfsd7fg/*/+bfjsdgf%$^") ; <== 1103173151
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
- JoeWinograd
- Posts: 2214
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Hash from string, hex or file, HMAC, Salt
Hi jNizM,
First, thank you for posting this — great stuff!
My script encrypts a string with a call to your SHA512 function, which works fine. Later on in the script, I want to decrypt the encrypted string, but I don't see a function to do that. Is there one? Thanks, Joe
First, thank you for posting this — great stuff!
My script encrypts a string with a call to your SHA512 function, which works fine. Later on in the script, I want to decrypt the encrypted string, but I don't see a function to do that. Is there one? Thanks, Joe
Re: Hash from string, hex or file, HMAC, Salt
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
- JoeWinograd
- Posts: 2214
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Hash from string, hex or file, HMAC, Salt
Yes, thank you! Brain cramp on my part. Sorry about that. Regards, JoeHashing != En-/Decryption
Re: Hash from string, hex or file, HMAC, Salt
New updates will be shared here => CNG (Cryptography API: Next Generation)
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 94 guests