

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Exclusive or (XOR)
incomplete
2: XOR Quiz
incomplete
3: One Time Pad
incomplete
4: Perfect Security
incomplete
This lesson's interactive features are locked, please to keep using them
A cipher is said to have perfect security if an attacker who has access to only the ciphertext can infer absolutely nothing of interest about the plaintext. Such perfect ciphers do exist, one such example is the "one-time pad".
Click to play video
The ^ operator will XOR two bytes. This cheat-sheet may be helpful.
byte1 := 0b01110000
byte2 := 0b10101000
xorRes := byte1 ^ byte2
fmt.Printf("%b\n", xorRes)
// 11011000
While the One Time Pad is a very powerful cipher, it's also very difficult to use in practice. That said, our product managers have found a use case in Passly that isn't overly inconvenient, so they've asked us to implement it.
Complete the crypt function. It accepts some data and a key as slices of bytes, and returns the result of an XOR operation on all the bits.
For example:
data = "0110100001100101011011000110110001101111"
key = "0111001101101010011001100111010101100100"
output = "0001101100001111000010100001100100001011"
Because XOR encryption is the perfect inverse of XOR decryption, the encrypt() and decrypt() will be identical in functionality. That's why we're writing a single crypt function that's used directly by the encrypt and decrypt functions. It makes the code easier to understand and use.