Skip to content
CoreSource checked

One-Time Pad

Encrypts a message by combining it with a truly random key used exactly once.

Quick Facts

Compact metadata for implementation and discovery.

Category
Cryptography
Difficulty
Beginner
Family
Symmetric Encryption
Tier
Core
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
1
Code example
Ready
Visualization
Ready

Overview

A one-time pad can hide plaintext perfectly only when the pad is random, secret, as long as the message, and never reused.

Core Concepts

secret padxor encryptionsingle useperfect secrecymisuse resistanceparameter validation

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(n)

Average

O(n)

Worst

O(n)

Space

O(n)

When to Use

  • Use when protecting messages needs secret pad.
  • Use when the input matches the assumptions behind symmetric Encryption.

When Not to Use

  • Avoid when a well-reviewed library already provides the primitive for production use.
  • Avoid when a simpler algorithm gives the required result with less setup.

What It Does

  • Encrypts a message by combining it with a truly random key used exactly once
  • Uses secret pad and xor encryption to guide the work.
  • Produces ciphertext, digest, proof, or derived key.

Use Cases

  • Protecting messages
  • Authenticating data
  • Deriving or managing cryptographic material

Inputs

  • Secret key or public parameters
  • Message or secret data
  • Nonce, salt, or context where needed

Outputs

  • Ciphertext, digest, proof, or derived key

Key Formulas (1)

One-time pad encryption

ciphertext = plaintext xor pad
ciphertext = plaintext xor pad

Combines each message bit with the matching random pad bit.

Pseudocode

  1. 1.Validate keys, nonces, salts, group parameters, and input ranges
  2. 2.Apply the primitive's block, hash, group, or reduction operation
  3. 3.Combine intermediate values exactly as the construction specifies
  4. 4.Return the protected value, proof, signature, derived key, or verification result

Canonical Example

Input
message = 'pay 10' with configured keys, nonces, or public parameters
Output
Ciphertext, digest, proof, or derived key
Explanation
One-Time Pad applies secret pad to produce ciphertext, digest, proof, or derived key.

Implementation Notes

  • Use constant-time library implementations for real systems instead of hand-written primitives.
  • Keep the secret pad step separate enough to test independently.
  • Use reviewed libraries and protocol specifications for production security-sensitive code.

Common Pitfalls

  • Reusing nonces, salts, pads, or domain parameters can destroy the intended security property.
  • Test edge cases, not only clean examples.
  • Treating educational pseudocode as production crypto can hide nonce, parameter, and side-channel requirements.

Interactive Mechanism Walkthrough

Graph Frontier & Edge Relaxation

Show the major cryptographic rounds or data dependencies without exposing secrets.

One-Time Pad mechanism walkthrough step 1 of 4suvwxt
Step 1 of 4: Validate keys, nonces, salts, group parameters, and input ranges
cryptography-mechanism

Notes

One-Time Pad should be used with the assumptions and tradeoffs of symmetric Encryption in mind.

Sources (1)

What each reference supports for this entry.

Handbook of Applied Cryptography

Book

Cryptography reference covering perfect secrecy and one-time pad requirements.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Conceptual neighborAES

Both are symmetric encryption methods, but the one-time pad requires single-use random keys.

Related Algorithms

Tags

CryptographySymmetric KeySecurityClassic