OTP(One Time Pad)

박서경박서경
4 min read

The One-Time Pad (OTP) is the only symmetric cipher that offers theoretical perfect secrecy. No matter how powerful the attacker, it's impossible to derive the plaintext from the ciphertext alone—if the key is truly random, used only once, and kept secret.


🔐 What Is the One-Time Pad?

  • Definition: The One-Time Pad takes a plaintext PP, a random key KK of the same length, and outputs ciphertext C using bitwise XOR:

    C=P⊕K

  • Decryption: Simply XOR the ciphertext with the same key:

    P=C⊕K

  • XOR property:

  • A⊕B⊕B=A. So XOR-ing the same key twice cancels it out.


🧮 Example

  • Plaintext PP: 01101101

  • Key KK: 10110100

  • Ciphertext CC: 01101101 ⊕ 10110100 = 11011001

  • Decryption: 11011001 ⊕ 10110100 = 01101101


🚨 Rule #1: Never reuse the key

If the same key is used for two messages:

C1=P1⊕K, C2=P2⊕K

⇒C1⊕C2=P1⊕P2

This reveals the XOR of the two plaintexts—leaking critical information. If an attacker knows one plaintext, they can fully recover the other.


💡 Advantages

FeatureDescription
SecurityPerfect secrecy (unbreakable)
SpeedExtremely fast (XOR is cheap)
SimplicityVery simple algorithm

⚠️ Practical Limitations

IssueExplanation
Key lengthThe key must be as long as the message
Key reuseKeys must be truly random and used only once
Key sharingSecurely transmitting the key itself is a separate challenge
StorageTo encrypt 1TB, you need a separate 1TB of random key storage

📜 Real-World Usage

  • Used by British SOE in WWII, KGB spies, NSA, and even Swiss bankers

  • Still used today in ultra-secure environments


🔐 Why Is the One-Time Pad Secure?

The One-Time Pad (OTP) is the only known cipher that offers perfect secrecy—a guarantee that not even an attacker with infinite computing power can learn anything about the plaintext just by seeing the ciphertext.


📐 Claude Shannon’s Proof of Perfect Secrecy

In the 1940s, Claude Shannon, the father of information theory, formally proved that perfect secrecy is only possible if:

  • The key is truly random

  • The key is at least as long as the plaintext

  • The key is used only once

This is the core of the One-Time Pad's security.


🧠 Why Is It Secure?

The core idea is simple:
If the key KK is random, then the ciphertext C=P⊕KC=P⊕K is also random from the attacker’s perspective—because XORing any fixed string with a truly random string produces a uniformly random result.

For example:

  • The probability that the first bit of a truly random key XORed with a plaintext bit equals 0 is ½

  • This holds for every bit independently

  • Therefore, every possible plaintext of the same length remains a valid guess

In short:

Without knowing the key, every plaintext is equally likely.


🎯 Example

If a ciphertext is 128 bits long:

  • There are 21282128 possible plaintexts.

  • If the key is also 128 bits and randomly chosen, an attacker cannot eliminate a single possibility.

But if the key is only 64 bits:

  • The attacker can try all 264264 keys and rule out the rest.

  • That leaks information—perfect secrecy is broken.


⚠️ Why It’s Not Practical

RequirementChallenge
Random keyMust be as long as the message
One-time useKey reuse breaks security
Secure distributionMust send the key securely first

Imagine encrypting a 1TB drive—you’d need 1TB of random key stored and securely shared.


✅ Summary

ItemDescription
EncryptionC=P⊕K
DecryptionP=C⊕K
SecurityPerfect secrecy
ConditionsKey = random, same length as message, used once
DrawbackHighly impractical for most modern use cases

✅ Summary

FeatureOne-Time Pad
SecurityPerfect secrecy (proven)
Key requirementRandom, same length as plaintext
ReuseAbsolutely not allowed
PracticalityLow — only used in rare scenarios

Next up: how modern encryption achieves practical security without massive keys.

0
Subscribe to my newsletter

Read articles from 박서경 directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

박서경
박서경