All problems
XOR Secret Shares
Problem
Split an integer secret into three XOR shares: pick two random-looking shares r1 and r2, and set the third to secret ^ r1 ^ r2. Return [r1, r2, r1 ^ r2 ^ secret]. Any single share alone reveals nothing about the secret.
Hint
XORing all three shares recovers the secret.
Test cases
case 1
in: [5,3,6]
expected: [3,6,0]
case 2
in: [42,1,2]
expected: [1,2,41]
case 3
in: [0,0,0]
expected: [0,0,0]
case 4
in: [255,170,85]
expected: [170,85,0]
Starter codePython
def xor_secret_shares(secret, r1, r2):
# Your code here
pass4 test cases · run your code against them in the editor