A one-time pad encrypts data by combining each plaintext byte with equally long random dummy data. Encryption produces two components: the pad and the encrypted product. Either component alone is useless; recombining both recovers the plaintext. section 1.3
For the technique to provide its intended protection, the dummy data must be:
- As long as the original data, preventing repeated patterns caused by a short pad. section 1.3
- Random and completely secret; reused or partially revealed pad data gives an attacker a clue. section 1.3
Swift byte-oriented implementation
Represent keys as [UInt8], generate a pad with the plaintext's UTF-8 byte count, and XOR corresponding bytes. Since A ^ B = C and C ^ B = A, decrypting XORs the two resulting keys again and converts the bytes back to a String. The demonstrated generator uses arc4random_uniform(), which is close to random for the example but not truly random. section 1.3
Original Data + Dummy Data -Encryption> Key-Pair (Dummy Data, Product) -Decryption> Original Data
Follow the encryption and decryption flow from original data to separated key pair and back again. section 1.3
One-time pads are impractical for general encryption because both parties must possess the same secret pad. A practical variation is to implement the technique for encrypting and decrypting images. section 1.6 section 1.7

