

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:
Is hard to reverse
Has a fixed output size
Is deterministic
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 = 10000000result := a ^ bComplete the hash() function. It takes an arbitrarily sized []byte and returns a fixed size [4]byte.
It should do the following:
Rotate the bits in each byte left 3 bits, do this one byte at a time
Shift the bits in each byte left 2 bits, do this one byte at a time
Create a new empty "final" array of exactly 4 bytes
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.