Skip to content

Instantly share code, notes, and snippets.

@madhavanmalolan
Created June 12, 2022 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madhavanmalolan/48f1e7064414f36e653feebf0bc240d6 to your computer and use it in GitHub Desktop.
Save madhavanmalolan/48f1e7064414f36e653feebf0bc240d6 to your computer and use it in GitHub Desktop.
import "utils/casts/u64_to_bits" as unpack64
from "hashes/sha3/256bit" import sha3_256 as hash
import "utils/casts/u8_from_bits" as pack8
def bits_to_u8_array<N, P>(bool[N] bits) -> u8[P]:
assert(N == 8 * P)
u8[P] res = [0; P]
for u32 i in 0..P do
res[i] = pack8(bits[8 * i..8 * (i + 1)])
endfor
return res
def main(u64[4] message, u64[4] h) -> bool:
bool[ 64*4 ] message_bits = [...unpack64(message[0]), ...unpack64(message[1]), ...unpack64(message[2]),...unpack64(message[3])]
u8[ 64*4 / 8 ] message_u8 = bits_to_u8_array(message_bits)
u64[4] m_hash = hash(message_u8)
assert(m_hash == h)
return true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment