Perfect Secrecy and the One-Time Pad

Imagine an adversary with unlimited time and unlimited computing power. Suppose they also have access to every ciphertext ever sent. Could such an adversary still learn nothing about the message? This question sounds impossible to answer affirmatively. Yet cryptography has a precise, provable "yes" — under the right conditions. The Classical Ciphers and Substitution schemes you have already studied, like the Caesar and Vigenère ciphers, all fall to statistical Cryptanalysis of Classical Ciphers. This happens precisely because ciphertext leaks structural information about plaintext, however faint. This article defines perfect secrecy, the strongest possible notion of confidentiality. It also proves that one specific construction — the one-time pad — actually achieves it. This is not an engineering approximation or a "hard in practice" argument. It is a mathematical theorem about probability distributions. The one-time pad is the only encryption scheme most students will ever encounter whose security is proven absolutely. No assumption is made about the adversary's computational power. The importance of this result is both historical and conceptual. Historically, one-time pads were used for the hottest of diplomatic and intelligence traffic. Examples include the Moscow–Washington hotline and Soviet spy communications broken only by key-reuse errors (the Venona decryptions). Other high-stakes channels also relied on them, where absolute secrecy justified enormous key-management overhead. Conceptually, perfect secrecy is the yardstick against which every later notion of security is measured. Ultimately, though, it is abandoned in practice. This happens because it comes at a cost so severe that virtually no real system can afford it. This article builds Shannon's formal definition of perfect secrecy from first principles. It walks through the one-time pad algorithm step by step. It then proves the algorithm satisfies the definition. Equally importantly, it proves that the scheme cannot be improved. Any perfectly secret scheme must have a key at least as long as the message. This impossibility result is what forces all of modern cryptography toward the computational relaxations. Later material builds on these relaxations.

Key takeaways
  • Perfect secrecy means the ciphertext reveals zero information about the plaintext, even to an adversary with infinite computing power.
  • It is formalized as a statement about probability distributions: the posterior distribution over plaintexts, given the ciphertext, equals the prior distribution.
  • The one-time pad (OTP) XORs a message with a truly random key of equal length, used exactly once.
  • The OTP is proven to satisfy Shannon's perfect secrecy definition via a clean bijection argument.
  • Shannon's theorem shows perfect secrecy forces the key to be at least as long as the message — an unavoidable cost, not an engineering oversight.
  • This impossibility is the reason real systems abandon perfect secrecy for computational security, motivating everything that follows in modern cryptography.
The core insight

A cipher is perfectly secret exactly when its ciphertext distribution is statistically independent of the plaintext, and the one-time pad achieves this only when the key is truly random, as long as the message, and never reused.

The idea

Perfect secrecy is a property of an entire encryption scheme, defined over probability distributions rather than over specific messages. Fix a plaintext space M\mathcal{M}, a ciphertext space C\mathcal{C}, and a key space K\mathcal{K}. Assume the key KK is drawn from some distribution (for the OTP, uniformly at random) independent of the message MM, which itself is drawn from some distribution over M\mathcal{M} representing the adversary's prior beliefs. Encryption is a function C=EncK(M)C = \mathrm{Enc}_K(M).

Definition (Shannon, 1949). An encryption scheme is perfectly secret if for every distribution over M\mathcal{M}, every message m∈Mm \in \mathcal{M}, and every ciphertext c∈Cc \in \mathcal{C} with Pr⁡[C=c]>0\Pr[C = c] > 0,

Pr⁡[M=m∣C=c]=Pr⁡[M=m].\Pr[M = m \mid C = c] = \Pr[M = m].

In words: observing the ciphertext changes nothing about the adversary's beliefs about the message. The posterior equals the prior. This is the cryptographic analogue of statistical independence between the random variables MM and CC. An equivalent and often more convenient formulation is stated purely in terms of ciphertexts:

Equivalent definition. A scheme is perfectly secret iff for every two messages m0,m1∈Mm_0, m_1 \in \mathcal{M} and every ciphertext c∈Cc \in \mathcal{C},

Pr⁡[EncK(m0)=c]=Pr⁡[EncK(m1)=c],\Pr[\mathrm{Enc}_K(m_0) = c] = \Pr[\mathrm{Enc}_K(m_1) = c],

where the probability is taken only over the choice of key KK. This says the same ciphertext is produced with the same probability no matter which plaintext generated it — so seeing cc gives no way to distinguish which message was sent. This "indistinguishability" phrasing is exactly the ancestor of the computational indistinguishability games used later in Computational Security and the Adversary Model. The one-time pad is a concrete cipher over bit strings. Let M=C=K={0,1}n\mathcal{M} = \mathcal{C} = \mathcal{K} = \{0,1\}^n. The key KK is sampled uniformly at random from {0,1}n\{0,1\}^n, independent of MM, and:

EncK(M)=M⊕K,DecK(C)=C⊕K,\mathrm{Enc}_K(M) = M \oplus K, \qquad \mathrm{Dec}_K(C) = C \oplus K,

where ⊕\oplus denotes bitwise XOR. The scheme requires three conditions that are easy to state but hard to satisfy operationally: the key must be (1) truly random, (2) as long as the message, and (3) never reused for a second message. Violating any one of these destroys the security proof, not merely weakens it — a fact history has demonstrated expensively.

How it works

The mechanical procedure is almost embarrassingly simple compared to the depth of the proof it enables. The subtlety lives entirely in key management: generating true randomness, distributing it securely in advance, and guaranteeing it is destroyed after a single use. ``` // One-Time Pad — Setup (performed once, in advance, over a secure channel) function GenerateAndSharePad(n): K := SampleUniformRandomBits(n) // true randomness, e.g. physical entropy source send K to sender via secure out-of-band channel send K to receiver via secure out-of-band channel // both parties store K; it must never be reused or logged return K // Encryption function Encrypt(M, K): require length(M) == length(K) C := empty bit string for i := 1 to length(M): C[i] := M[i] XOR K[i] DestroyAfterUse(K) // mark this key material as spent return C // Decryption function Decrypt(C, K): require length(C) == length(K) M := empty bit string for i := 1 to length(C): M[i] := C[i] XOR K[i] DestroyAfterUse(K) return M ``` Correctness of decryption is immediate from the algebra of XOR: for every bit,

(Mi⊕Ki)⊕Ki=Mi⊕(Ki⊕Ki)=Mi⊕0=Mi,(M_i \oplus K_i) \oplus K_i = M_i \oplus (K_i \oplus K_i) = M_i \oplus 0 = M_i,

using associativity, commutativity, and the facts Ki⊕Ki=0K_i \oplus K_i = 0 and Mi⊕0=MiM_i \oplus 0 = M_i. So DecK(EncK(M))=M\mathrm{Dec}_K(\mathrm{Enc}_K(M)) = M always — this is perfect correctness, separate from and prerequisite to the perfect secrecy proof below. The architecture that makes this usable in practice — and the reason it is so rarely used — is shown below: the pad must be generated and physically transported before any message exists, then consumed bit-for-bit and never touched again.

Figure
One-time pad lifecycle: generation, one-time transport, single-use consumption
Random Source K = 10110...01 secure courier Sender copy of K Receiver copy of K M = HELLO C = M XOR K (sent on open channel) public network M = C XOR K recovered K is destroyed by both parties — used exactly once

Complexity & correctness

Time and space complexity. Encryption and decryption are both O(n)O(n) time and O(n)O(n) additional space, where nn is the message length in bits — a single pass computing bitwise XOR, the cheapest possible operation on any architecture. There is no asymptotic overhead at all compared to sending the plaintext in the clear. The real cost is key material: the scheme consumes nn fresh, truly random key bits per message bit sent, and this key must be generated, transported, stored, and destroyed out of band. This is an O(n)O(n) space and (usually) an O(n)O(n) secure-channel-bandwidth cost, which for high-volume communication is the scheme's fatal practical flaw.

Correctness of decryption was shown above via the XOR self-inverse identity — this holds unconditionally, for every key and message, with probability 1.

Proof that the OTP is perfectly secret. Fix any message m∈{0,1}nm \in \{0,1\}^n and any ciphertext c∈{0,1}nc \in \{0,1\}^n. Because KK is uniform over {0,1}n\{0,1\}^n and independent of MM,

Pr⁡[EncK(m)=c]=Pr⁡[m⊕K=c]=Pr⁡[K=c⊕m].\Pr[\mathrm{Enc}_K(m) = c] = \Pr[m \oplus K = c] = \Pr[K = c \oplus m].

Since KK is uniform over all 2n2^n strings, Pr⁡[K=c⊕m]=1/2n\Pr[K = c \oplus m] = 1/2^n for every fixed mm and cc — the value c⊕mc \oplus m is just one particular string, and the uniform distribution assigns the same probability 1/2n1/2^n to every string. Hence

Pr⁡[EncK(m)=c]=12nfor all m,c.\Pr[\mathrm{Enc}_K(m) = c] = \frac{1}{2^n} \quad \text{for all } m, c.

This value does not depend on mm at all. So for any two messages m0,m1m_0, m_1,

Pr⁡[EncK(m0)=c]=12n=Pr⁡[EncK(m1)=c],\Pr[\mathrm{Enc}_K(m_0) = c] = \frac{1}{2^n} = \Pr[\mathrm{Enc}_K(m_1) = c],

which is exactly the ciphertext-indistinguishability form of perfect secrecy stated earlier. A short Bayes'-rule computation converts this into Shannon's original posterior-equals-prior form: since Pr⁡[C=c∣M=m]=1/2n\Pr[C=c \mid M=m] = 1/2^n is the same constant for every mm,

Pr⁡[M=m∣C=c]=Pr⁡[C=c∣M=m]Pr⁡[M=m]Pr⁡[C=c]=(1/2n)Pr⁡[M=m]∑m′(1/2n)Pr⁡[M=m′]=Pr⁡[M=m],\Pr[M = m \mid C = c] = \frac{\Pr[C = c \mid M = m]\Pr[M=m]}{\Pr[C=c]} = \frac{(1/2^n)\Pr[M=m]}{\sum_{m'} (1/2^n)\Pr[M=m']} = \Pr[M=m],

because the constant 1/2n1/2^n cancels out of numerator and denominator entirely. ■\blacksquare The intuitive reading of this proof: for every possible plaintext mm, there is exactly one key that maps it to the observed ciphertext cc — namely K=c⊕mK = c \oplus m — and that key is exactly as likely as any other. Encryption under a uniform key is a bijection on {0,1}n\{0,1\}^n for each fixed key, and averaging a bijection over a uniform key distribution produces a uniform, plaintext-independent ciphertext distribution. This bijection argument is the real engine of the proof and generalizes to any perfectly secret scheme over a group.

Shannon's impossibility theorem (key length lower bound). Perfect secrecy is not free — it forces ∣K∣≥∣M∣|\mathcal{K}| \geq |\mathcal{M}|. Proof sketch. Suppose ∣K∣<∣M∣|\mathcal{K}| < |\mathcal{M}|. Fix any ciphertext cc that occurs with nonzero probability, and consider the set of plaintexts reachable from cc by some key: Sc={Deck(c):k∈K}S_c = \{ \mathrm{Dec}_k(c) : k \in \mathcal{K} \}. Since decryption for each fixed key is a function, ∣Sc∣≤∣K∣<∣M∣|S_c| \leq |\mathcal{K}| < |\mathcal{M}|. So there exists some plaintext m∗∉Scm^* \notin S_c — a message that no key at all can map to cc. Then Pr⁡[C=c∣M=m∗]=0\Pr[C = c \mid M = m^*] = 0, while for a distribution assigning m∗m^* positive prior probability, perfect secrecy would require Pr⁡[C=c∣M=m∗]=Pr⁡[C=c]>0\Pr[C = c \mid M = m^*] = \Pr[C=c] > 0 whenever Pr⁡[C=c]>0\Pr[C=c]>0 — a contradiction, since 0≠Pr⁡[C=c]>00 \ne \Pr[C=c] > 0. Hence no scheme with ∣K∣<∣M∣|\mathcal{K}| < |\mathcal{M}| can be perfectly secret. ■\blacksquare This means the one-time pad's key length — one full bit of key per bit of message — is not a naive or lazy design choice. It is provably optimal and unavoidable for any perfectly secret scheme. Every attempt to "compress" the key while keeping perfect secrecy is doomed by this counting argument; this is precisely the wall that motivates relaxing to computational security, covered in Limitations of Perfect Secrecy and Computational Security and the Adversary Model.

Honest tradeoffs. The OTP is unconditionally, information-theoretically secure — but only under three fragile assumptions: true (not pseudo-)randomness, one-time use, and secure prior key distribution of a length matching total future traffic. It provides no message authentication or integrity — an attacker who knows or guesses part of the plaintext can flip corresponding ciphertext bits to flip the plaintext bits, since XOR is malleable. It also provides no protection if the key is ever reused: XOR-ing two ciphertexts under the same key cancels the key entirely, C1⊕C2=M1⊕M2C_1 \oplus C_2 = M_1 \oplus M_2, exposing the XOR of the two plaintexts — the exact failure mode that broke real Venona traffic.

Worked example

Take a short ASCII message and trace both the encryption and the proof idea concretely. Let M=M = `"HI"`, represented in binary (8-bit ASCII per character):

SymbolASCIIBinary
H72`01001000`
I73`01001001`

Concatenated plaintext:

M=01001000 01001001M = 01001000\ 01001001

Sample a truly random key of equal length (16 bits):

K=11010110 00111010K = 11010110\ 00111010

Compute C=M⊕KC = M \oplus K bit by bit:

PositionMKC = M⊕K
1–8 (H)010010001101011010011110
9–16 (I)010010010011101001110011

So C=10011110 01110011C = 10011110\ 01110011, which as bytes is `0x9E 0x73` — not printable ASCII, and structurally no different in appearance from the ciphertext of any other two-letter message.

Decryption, at the receiver, recomputes C⊕KC \oplus K:

PositionCKM = C⊕K
1–8100111101101011001001000 = H
9–16011100110011101001001001 = I

Correctly recovers `HI`.

Now the security argument, made concrete. Suppose an eavesdropper intercepts C=10011110 01110011C = 10011110\ 01110011 and tries to guess whether MM was `"HI"` or some other message, say `"NO"` (`01001110 01001111`). For the adversary's guess to be consistent, there must exist a key K′K' with C=M′⊕K′C = M' \oplus K':

K′=C⊕M′=10011110 01110011 ⊕ 01001110 01001111=11010000 00111100.K' = C \oplus M' = 10011110\,01110011 \ \oplus\ 01001110\,01001111 = 11010000\,00111100.

This is a perfectly valid, equally likely 16-bit string — just as likely to have been the true key as the one that actually produced `"HI"`. Every candidate plaintext of the correct length is consistent with the observed ciphertext under some key, and every one of those keys is equally probable (1/2161/2^{16}) under a uniform key distribution. The ciphertext therefore supplies zero evidence favoring `"HI"` over `"NO"` or any other 16-bit message — exactly the bijection argument from the proof above, instantiated on real bytes.

Common pitfalls & traps

PitfallWhy it breaks the guarantee
Reusing the same key for two messagesC1⊕C2=M1⊕M2C_1 \oplus C_2 = M_1 \oplus M_2 leaks the XOR of both plaintexts; classical crib-dragging then recovers both messages, as in Venona
Using a pseudorandom generator instead of true randomnessBreaks the uniform-key assumption in the proof; the key is now a deterministic function of a short seed, so the scheme is only as secure as the seed, not perfectly secret
Key shorter than the message (padding/repeating it)Violates Shannon's ∣K∣≥∣M∣|\mathcal{K}| \geq |\mathcal{M}| bound; the cipher degenerates into a repeating-key XOR, vulnerable to frequency analysis exactly like the Vigenère cipher
Believing OTP gives integrity or authenticationXOR ciphers are malleable — flipping a ciphertext bit flips the corresponding plaintext bit predictably, with no detection mechanism
Confusing "perfectly secret" with "unbreakable forever"Perfect secrecy is about this ciphertext leaking no information; it says nothing about key distribution security, physical key theft, or side channels
Treating perfect secrecy as achievable "in general"The key-length lower bound proves it is mathematically impossible to beat ∣K∣≥∣M∣|\mathcal{K}| \geq |\mathcal{M}| — no clever scheme escapes this

Pioneers & history

The one-time pad's engineering lineage traces to Gilbert Vernam, an AT&T engineer who patented a telegraph cipher combining plaintext with a random key stream in 1919, and to Joseph Mauborgne, who recognized that the key must be non-repeating and random to resist cryptanalysis. But the mathematical proof that such a scheme achieves absolute secrecy — and the very definition of perfect secrecy itself — came three decades later from Claude Shannon, whose 1949 paper "Communication Theory of Secrecy Systems" founded information-theoretic cryptography as a rigorous discipline.

Origins · 1 minClaude Elwood Shannon and how this was discovered
CE
Claude Elwood Shannon
1916–2001 · Bell Labs, founder of information theory and information-theoretic cryptography

Shannon's wartime work on cryptography, partly classified until after WWII, ran in parallel with his development of information theory. His 1949 paper gave the first rigorous mathematical definition of "unbreakable" encryption and proved the one-time pad meets it — while also proving that no scheme can do better in key economy. This dual result, a positive construction paired with a matching impossibility theorem, set the template that all later security definitions (semantic security, indistinguishability, zero-knowledge) would follow.

History
1917
— Vernam devises a telegraphic XOR-style cipher with a repeating key tape.
1919
— Mauborgne proposes making the key truly random and non-repeating, yielding the modern one-time pad.
1945–1949
— the Venona program begins collecting Soviet one-time-pad traffic later broken due to key reuse.
1949
— Shannon publishes "Communication Theory of Secrecy Systems," formally defining and proving perfect secrecy.
1954–1980
s — one-time pads used operationally for the Moscow–Washington hotline and high-assurance diplomatic and intelligence channels.

Where this matters

Genuine one-time pads are used today only where key-distribution cost is acceptable relative to the value of absolute secrecy: certain diplomatic cables, some historical intelligence-agency communications, and specialized quantum key distribution deployments that use Quantum Key Distribution specifically to generate the fresh, truly random, shared key material an OTP needs. The core cryptographic lesson, however, permeates far beyond literal OTP use. Stream ciphers such as RC4 and the keystream generators inside AES-CTR mode are engineered as pseudorandom approximations of the one-time pad — same XOR-with-keystream structure, but with a short seed expanded computationally, trading Shannon's perfect guarantee for a computational one. Every proof of security for a modern stream cipher or block cipher mode implicitly measures itself against the OTP's ideal and asks how closely a computationally bounded adversary can be kept from distinguishing the real ciphertext from a true one-time-pad ciphertext. This comparison is the conceptual bridge into Computational Security and the Adversary Model, where the "any distribution, any adversary, forever" bar of perfect secrecy is relaxed to "no efficient adversary, with overwhelming probability" — the compromise that makes practical, scalable cryptography possible.

:::quiz[In the proof that OTP satisfies perfect secrecy, what key fact makes Pr[Enc_K(m) = c] independent of m?]

  • The key is derived from the message using a hash function
  • For any fixed m and c, exactly one key value c⊕m produces that ciphertext, and all keys are equally likely ✓
  • The ciphertext space is smaller than the key space
  • Encryption is a randomized, non-deterministic function of m alone

Ask the tutor: Why does relaxing "any adversary" to "any efficient adversary" let modern ciphers reuse short keys without violating Shannon's impossibility theorem?

Is the one-time pad used in real internet security protocols like TLS?

No. TLS and virtually all deployed protocols use computationally secure ciphers such as AES or ChaCha20, not true one-time pads. The OTP requires a truly random key as long as the total message traffic, pre-shared over a secure channel before communication begins — completely impractical for internet-scale, on-demand communication with strangers. Stream ciphers mimic the OTP's XOR-with-keystream structure but generate the keystream computationally from a short shared seed, sacrificing perfect secrecy for a computational security guarantee that scales. The OTP survives today mainly in specialized, low-bandwidth, extremely high-assurance channels, and as the theoretical benchmark against which every other cipher's security is conceptually measured.

Does perfect secrecy mean the cipher is unbreakable forever, even with future computers?

Yes, in a precise mathematical sense — a perfectly secret ciphertext contains literally zero information about the plaintext, so no computer, however powerful or futuristic, can extract a preference for one plaintext over another purely from the ciphertext. This differs fundamentally from schemes like AES, which are only computationally secure: breaking them is currently infeasible but not proven impossible in principle. Perfect secrecy's guarantee holds regardless of computational advances, including quantum computers, because it is a statement about probability distributions, not about the difficulty of a computational problem. The catch is that this absolute guarantee requires the fragile OTP conditions to hold exactly.

Why can't we just reuse a short random key to save on key distribution cost?

Because reuse destroys the exact independence the proof relies on. If the same key K encrypts two messages, an eavesdropper computes C1⊕C2=M1⊕M2C_1 \oplus C_2 = M_1 \oplus M_2, which is no longer independent of the plaintexts — it directly reveals their relationship, and if either message (or partial structure, like common words) is guessed, classical techniques recover both. This is not a minor weakening; it collapses the scheme into something analyzable with the same statistical tools used against classical substitution ciphers. Historically, exactly this mistake — reusing one-time pad key material under wartime pressure — allowed the Venona project to decrypt some Soviet intelligence traffic decades later.

Does a pseudorandom number generator (PRNG) key make the one-time pad still perfectly secret?

No, and this is one of the most common misconceptions. The perfect secrecy proof relies on the key being drawn from the full uniform distribution over all possible keys, with genuinely maximal entropy. A PRNG key is a deterministic function of a much shorter seed, so the effective key space collapses to the (much smaller) set of reachable outputs of the generator. Shannon's own key-length lower bound then applies: since the entropy of the seed is smaller than the message length, the scheme cannot be perfectly secret, only at best computationally secure — assuming the PRNG is cryptographically strong. This exact substitution is what stream ciphers like RC4 or ChaCha20 do deliberately.

How does the key-length lower bound relate to compression and entropy?

The lower bound ∣K∣≥∣M∣|\mathcal{K}| \geq |\mathcal{M}| is really a statement about entropy: to perfectly mask H(M)H(M) bits of message entropy, you need at least H(M)H(M) bits of independent key entropy, because XOR-ing with a key can add at most as much uncertainty as the key itself contains. This is the same intuition behind Shannon's source-coding results — you cannot manufacture information (in this case, secrecy) from nothing. Attempts to "compress" the key using a shorter seed just relocate the entropy bottleneck to the seed, which is exactly the PRNG situation discussed above. This is why perfect secrecy and data compression are, in a precise sense, two faces of the same information-theoretic coin.

What is the difference between perfect secrecy and semantic security?

Perfect secrecy is an information-theoretic guarantee holding against any adversary, regardless of computational power, and requires key length at least equal to message length. Semantic security, used to analyze schemes like AES, is a computational relaxation: it requires that no efficient (polynomial-time) adversary can distinguish encryptions of two chosen messages with more than negligible advantage. Semantic security permits short, reusable keys because it only needs to defeat realistic, resource-bounded attackers, not omnipotent ones. Perfect secrecy is the ideal that motivates the definition of semantic security, and every proof of semantic security is essentially an argument that a scheme is computationally indistinguishable from a perfectly secret one.

Why does the OTP provide no protection against an active attacker who modifies the ciphertext?

Because XOR is a linear, malleable operation: flipping any bit of the ciphertext flips the corresponding bit of the decrypted plaintext, and the receiver has no built-in way to detect that this happened. An attacker who knows or guesses the plaintext structure (e.g., a fixed-format field) can flip specific bits to produce a chosen, predictable change in the decrypted message, all without knowing the key. Perfect secrecy is purely a confidentiality guarantee about what an eavesdropper can learn; it says nothing about integrity, i.e., whether a message was tampered with. Real systems needing both properties layer a separate message authentication code on top of encryption.

Before this

Where this leads