{
  "id": "one-time-pad",
  "title": "One-time Pad",
  "lang": "en",
  "source_lang": "en",
  "summary": "A one-time pad is an encryption system that achieves perfect secrecy by combining each message with an independent, uniformly random secret key used only once.",
  "category": "computer-science",
  "subcategory": "networks-security",
  "type": "concept",
  "aliases": [
    "OTP",
    "one-time pad cipher"
  ],
  "generated_at": "2026-11-03",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/one-time-pad/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/one-time-pad/",
      "json": "https://aiwiki.page/zh/one-time-pad.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A one-time pad is a method of encryption in which a message is combined with a secret, uniformly random key that is at least as long as the message and is never reused. When these conditions hold, the ciphertext reveals no information about the message’s contents to an observer who does not know the key. This property, called perfect secrecy, holds even against an adversary with unlimited computing power. The one-time pad is a fundamental result in cryptography, but its demanding requirements for key generation, distribution, storage, and use limit its practical deployment."
    },
    {
      "heading": "Operation",
      "text": "In its binary form, a one-time pad represents the message and key as sequences of bits of equal length. Encryption combines corresponding bits using exclusive OR, usually written \\(\\oplus\\):\n\n\\[C=M\\oplus K,\\]\n\nwhere \\(M\\) is the plaintext, \\(K\\) is the key, and \\(C\\) is the ciphertext. Exclusive OR produces 1 when its two inputs differ and 0 when they agree.\n\nDecryption applies the same operation with the same key:\n\n\\[M=C\\oplus K.\\]\n\nThis works because \\(K\\oplus K=0\\). For example:\n\nPlaintext:   10110010\nKey:         01101101\nCiphertext:  11011111\n\nApplying the key to the ciphertext recovers the plaintext:\n\nCiphertext:  11011111\nKey:         01101101\nPlaintext:   10110010\n\nThe same principle can be applied to symbols other than bits. If letters are represented by the numbers 0 through 25, encryption can add each plaintext symbol to its corresponding key symbol modulo 26, with decryption subtracting the key modulo 26. The key symbols must be independently and uniformly selected from the same alphabet.\n\nThe word pad comes from physical implementations in which correspondents possessed matching pads of random key material. Each sheet or section was used once and then destroyed. The mathematical construction does not depend on paper: keys can also be stored electronically."
    },
    {
      "heading": "Conditions for perfect secrecy",
      "text": "A one-time pad provides its defining guarantee only when all of the following conditions hold:\n\n- Uniform randomness: every possible key of the required length is equally likely. For a binary key, this means independent, unbiased bits.\n- Independence: the key is generated independently of the message.\n- Sufficient length: each message bit or symbol consumes a corresponding fresh key bit or symbol.\n- Single use: no part of the key is used to encrypt more than one part of the plaintext, whether within one message or across different messages.\n- Secrecy of the key: the adversary does not obtain the key material used for the message.\n\nThese conditions concern the key’s actual generation and handling, not merely its appearance. A long sequence that looks irregular is not necessarily random. Text from books, repeated passwords, and predictable sequences do not satisfy the requirements.\n\nA pseudorandom number generator expands a finite internal state or seed into a longer sequence. Even when such a generator is cryptographically strong, using its output as a pad does not generally provide the information-theoretic guarantee of a true one-time pad. Security instead depends on assumptions about the difficulty of distinguishing or predicting the generated sequence."
    },
    {
      "heading": "Why the ciphertext reveals no information",
      "text": "Perfect secrecy is a concept from information theory. Let \\(M\\), \\(K\\), and \\(C\\) denote the message, key, and ciphertext as random variables. Assume the message has a fixed length of \\(n\\) bits and the key is independently and uniformly selected from all \\(2^n\\) possible bit strings.\n\nFor every candidate message \\(m\\) and observed ciphertext \\(c\\), exactly one key makes them correspond:\n\n\\[k=m\\oplus c.\\]\n\nSince that key occurs with probability \\(2^{-n}\\),\n\n\\[\\Pr(C=c\\mid M=m)=2^{-n}.\\]\n\nThe ciphertext therefore has the same probability distribution regardless of which message was encrypted. Consequently,\n\n\\[\\Pr(M=m\\mid C=c)=\\Pr(M=m).\\]\n\nObserving the ciphertext does not change the adversary’s probability assessment of any candidate message.\n\nThis does not mean that every plaintext is equally likely. An observer may already know that some messages are more plausible than others. Perfect secrecy means the ciphertext provides no additional evidence for choosing among them.\n\nIt also explains why exhaustive key search cannot uniquely recover a one-time-pad message: trying every key produces every possible plaintext of the appropriate length. The ciphertext alone supplies no way to identify the original.\n\nThe key-length requirement\n\nShannon’s bound for perfectly secret encryption with error-free decryption states, under the standard assumptions, that\n\n\\[H(K)\\geq H(M),\\]\n\nwhere \\(H\\) denotes entropy.\n\nIf every \\(n\\)-bit message is possible and equally likely, the message entropy is \\(n\\) bits, so at least \\(n\\) bits of key entropy are required. More generally, supporting all \\(2^n\\) possible messages with perfect secrecy requires at least as many possible keys as messages.\n\nThe one-time pad is therefore not an inefficient implementation of something that could provide the same unrestricted guarantee from a tiny secret. Its key requirements reflect a fundamental information-theoretic limit."
    },
    {
      "heading": "Key reuse and other failure modes",
      "text": "Reusing a pad\n\nIf two messages are encrypted with the same key,\n\n\\[C_1=M_1\\oplus K,\\qquad C_2=M_2\\oplus K,\\]\n\nthen\n\n\\[C_1\\oplus C_2=M_1\\oplus M_2.\\]\n\nThe key cancels, exposing a relationship between the plaintexts. This is often called the two-time pad problem.\n\nIt does not automatically reveal both messages in every case. However, ordinary language, document formats, protocol headers, and other structured data contain substantial redundancy. Guesses about one plaintext can expose corresponding portions of the other. If an attacker knows one plaintext segment, the corresponding key segment follows directly:\n\n\\[K=M\\oplus C.\\]\n\nAny other material encrypted with that same segment is then exposed. Reusing only part of a pad compromises the corresponding portions of the messages.\n\nBiased or predictable keys\n\nIf some keys are more likely than others, ciphertext observations can favor some plaintexts over others. Correlations between key bits, defects in random-number generation, and deterministic patterns can likewise invalidate the proof of perfect secrecy.\n\nPhysical sources of randomness require engineering and statistical characterization; physical origin alone does not guarantee independent, uniformly distributed output.\n\nExposure of stored keys\n\nThe pad contains everything needed to decrypt the associated ciphertext. Copies in storage, backups, printed records, or compromised devices can therefore defeat the system without any cryptanalytic attack.\n\nPractical implementations must also track which key positions have been consumed. Lost state, restored backups, or overlapping allocations can cause accidental reuse."
    },
    {
      "heading": "Confidentiality does not provide authentication",
      "text": "A one-time pad by itself does not provide authentication or message integrity. An attacker can change the decrypted plaintext in a predictable way by modifying the ciphertext.\n\nIf the attacker replaces \\(C\\) with\n\n\\[C'=C\\oplus\\Delta,\\]\n\nthe recipient obtains\n\n\\[M'=C'\\oplus K=M\\oplus\\Delta.\\]\n\nThus, selected bit flips in the ciphertext produce the same bit flips in the plaintext. The attacker does not need to know the key, although knowledge of the message format may be needed to make a meaningful alteration.\n\nThis property is called malleability. Protecting against active modification requires an additional mechanism, such as a message authentication code, with suitable key separation and protocol design. Information-theoretic authentication is possible, but it is a separate construction with its own assumptions and forgery bounds.\n\nA one-time pad also does not inherently conceal message length, transmission time, communicating parties, or other metadata. Fixed-size messages and padding can reduce some length leakage, but the encryption operation itself does not provide traffic-flow confidentiality."
    },
    {
      "heading": "History",
      "text": "An early description of a related random-key cipher appeared in a proposal by Frank Miller in 1882. Gilbert Vernam developed a teleprinter encryption system in 1917 that combined message signals with a key stream. Joseph Mauborgne is associated with recognizing the importance of random, nonrepeating key material in this line of development.\n\nThe expression Vernam cipher is sometimes used for the one-time pad, but the terminology is not always exact: combining text with a key stream gives perfect secrecy only if that stream meets the one-time pad’s requirements.\n\nClaude Shannon established the mathematical theory of perfect secrecy in his 1949 paper Communication Theory of Secrecy Systems. His work explained both the security of the one-time pad and the limits on perfectly secret encryption.\n\nOne-time pads were used in military, diplomatic, and intelligence communications during the twentieth century. The VENONA project is a prominent example of the consequences of reuse: duplicated Soviet key material enabled cryptanalysis of portions of otherwise protected communications. The weakness lay in the handling and reuse of key material, not in a violation of the mathematical secrecy result."
    },
    {
      "heading": "Practical uses and limitations",
      "text": "The principal obstacle to widespread use is key distribution. To exchange a gigabyte of encrypted data, the correspondents need a gigabyte of matching, previously shared secret key material. Distributing that material may require a trusted courier, secure physical transfer, or another mechanism whose security must be considered separately.\n\nOne-time pads can nevertheless be useful where communication volumes are limited and key material can be distributed securely in advance. Their simple encryption operation can be implemented manually or electronically, while their security does not depend on a computational hardness assumption.\n\nMost modern communication systems instead use compact keys with practical symmetric encryption, such as the Advanced Encryption Standard, or with a stream cipher. Stream ciphers resemble a one-time pad operationally because they combine plaintext with a key stream, but they generate that stream from a shorter secret key. Their security is computational rather than perfect.\n\nUsing public-key cryptography to send a pad does not automatically give the overall system information-theoretic secrecy: an attacker who later breaks the key-transport mechanism may recover the pad. Similarly, quantum key distribution can supply key material for use in a one-time pad, but it requires an authenticated classical channel and remains subject to implementation assumptions.\n\nThe mathematical guarantee of a correctly implemented one-time pad is unaffected by a quantum computer or any other increase in computational power. It does not, however, protect against compromised endpoints, stolen pads, faulty randomness, key reuse, or unauthenticated message modification."
    }
  ],
  "links": [
    "encryption",
    "cryptography",
    "bit",
    "exclusive-or",
    "pseudorandom-number-generator",
    "information-theory",
    "random-variable",
    "probability-distribution",
    "information-entropy",
    "authentication",
    "message-authentication-code",
    "metadata",
    "advanced-encryption-standard",
    "public-key-cryptography",
    "quantum-key-distribution",
    "quantum-computer"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}