Fastest SHA256 Hash
This is over 4x times faster than Hashlib and the input has to be a buffer!
local Message: string = "Hello World"
local MessageBuffer: buffer = buffer.fromstring("Hello World")
local OptionalSalt: string = "Salt"
local OptionalSaltBuffer: buffer = buffer.fromstring("Salt")
assert(SHA256(MessageBuffer) == SHA256(buffer.fromstring(Message)))
assert(SHA256(MessageBuffer, OptionalSaltBuffer) == SHA256(buffer.fromstring(Message .. OptionalSalt)))
assert(SHA256(MessageBuffer, OptionalSaltBuffer) == SHA256(buffer.fromstring(Message), buffer.fromstring(OptionalSalt)))
assert(SHA256(buffer.fromstring("The quick brown fox jumps over the lazy dog.")) == "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c")
Benchmark Results
Iterations: 500
Message Length: 29204
HashLib took: 1524290 microseconds
Daily’s SHA256 (Old) took: 525492 microseconds - 190.1% faster than HashLib
Dekkonot’s SHA256 took: 358659 microseconds - 46.5% faster than Daily’s SHA256 (Old)
Daily’s SHA256 (Devforum) took: 325278 microseconds - 10.3% faster than Dekkonot’s SHA256
Download:
SHA256.rbxm (4.4 KB)