0Pricing
Cryptology Academy · Lesson

XOR Encryption & the One-Time Pad

Build a simple XOR cipher and discover its perfect-secrecy cousin.

Welcome

XOR encryption is simple: ciphertext = plaintext XOR key. When the key is truly random and used only once, we get the one-time pad — the only provably unbreakable cipher.

XOR Encryption Basics

key = bytes([0x5A, 0xF2, 0x3C, 0x11]) plaintext = bytes([0x48, 0x65, 0x6C, 0x6C]) # 'Hell' ciphertext = bytes(p^k for p,k in zip(plaintext,key)) # Result: 0x12 0x97 0x50 0x7D

All lessons in this course

  1. Bitwise Operations Refresher
  2. XOR Encryption & the One-Time Pad
  3. Why XOR Alone Is Not Secure
  4. XOR Inside AES & Stream Ciphers
← Back to Cryptology Academy