

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
click for more info
Not enough gems
Cost: 6 gems
1: Hash Functions
incomplete
2: Hash Collisions
incomplete
3: Hashmaps
incomplete
4: Deterministic
incomplete
5: One Way
incomplete
6: Toy Hash Function
incomplete
7: Toy Hash Review
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Let's build a toy hash function!
Our goal will be to build a function that:
Our function will not be suitable for production use, but will be useful for the Passly marketing team to explain how our security systems work from a high level.
To shift a byte left by numBits:
numBits := 3
// original = 11110000
shifted := original << numBits
// shifted = 10000000
result := a ^ b
Complete the hash() function. It takes an arbitrarily sized []byte and returns a fixed size [4]byte.
It should do the following:
XOR each byte with its corresponding byte in the final array, and save the result back to the final array. Do this one byte at a time for each byte in the rotated/shifted input. The "corresponding" byte in the final array is at index i%4, where i is the index of the byte in the input.