The one-time pad and why keys must never be reused
Symmetric encryption uses the same secret key to encrypt and decrypt. The simplest example is XOR: combining each message byte with a key byte using exclusive-or, and repeating the same operation with the same key to decrypt. The one-time pad does exactly this with a key that is truly random, as long as the message, kept secret, and used only once. Under those conditions it is provably unbreakable.
Python
def xor(data, key):
return bytes(d ^ k for d, k in zip(data, key))
plain1 = b"ATTACK AT DAWN"
plain2 = b"RETREAT AT TEN"
key = bytes(range(1, 15))
cipher1 = xor(plain1, key)
cipher2 = xor(plain2, key)
print(xor(cipher1, key) == plain1)
leak = xor(cipher1, cipher2)
print(leak == xor(plain1, plain2))
print(xor(leak, plain1))