← Cryptography guide

K023 / Symmetric ciphers (block and stream)

One-Time Pad

one-time pad · Survey date 2026-12-05

A one-time pad, also called a Vernam cipher, combines a message with a pre-shared key used only once.

CRYPTOGRAPHY LAB / K023

Cryptography Lab · One-Time Pad

Run real computations and inspect intermediate states step by step.

Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.

Scope: Toy educational example

One-Time Pad (XOR)

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Open lab →

Definition and overview
A one-time pad, also called a Vernam cipher, combines a message with a pre-shared key used only once. Source document ↗
Classification and reversibility
Reversible symmetric stream encryption/decryption using the same key. Source document ↗
Key or secret requirements
Requires a pre-shared secret key at least as long as plaintext, used only once. Source document ↗
Operating principle and structure
Combines plaintext and key bitwise/bytewise using XOR or modular addition. Source document ↗
Key size, block size and parameters
No fixed block; key must be at least message length and truly random. Source document ↗
Security strength and recommendation
Provides information-theoretic perfect secrecy, but key length and single-use requirements make it unsuitable for most modern environments. Source document ↗
Known attacks and vulnerabilities
Never reuse keys; large keys must be exchanged securely. Reuse critically weakens security. Source document ↗
Standards and certification
Not a certification standard itself; RFC 4086 (BCP 106) mentions OTP randomness quantity and requirements. Source document ↗
Typical uses
Historically used in espionage, military communications, diplomatic cables and high-value financial communications. Source document ↗
Implementations, libraries and tools
Educational/utilities include PyPI otp-text and Node.js, Rust and JavaScript libraries. Source document ↗
Decryption or decoding
Recover plaintext by applying XOR again with the same key, or the inverse modular operation. Source document ↗
Advantages
Perfect secrecy and very fast encryption/decryption. Source document ↗
Limitations and cautions
Key must be at least message length, making bulk transmission inconvenient and key management burdensome. Source document ↗
Distinguishing encryption, encoding and hashing
OTP can also mean One-Time Password, which is distinct from One-Time Pad encryption. Source document ↗

Practical examples

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

Example

Prepare a truly random key as long as plaintext, XOR bitwise or bytewise, and XOR again with the same key to restore plaintext. Use the key only once and dispose of it securely.

Procedure

Represent plaintext as bytes/bits, generate and pre-share a truly random key at least as long, apply XOR or modular addition, transmit ciphertext and discard the key. Receiver uses the same key with XOR or inverse modular operation. Base64 is transmission-format encoding, separate from OTP.

Scenario

Suitable for high-security low-bandwidth scenarios with secure pre-sharing of large random keys, such as historical military/diplomatic communications. Unsuitable for general internet and bulk data; best limited to education/prototypes.

Pitfalls and alternatives

Avoid reuse, predictable randomness, key exposure and disposal failures. OTP alone lacks authentication/integrity. Use AES-GCM or similar AEAD and secure key management for ordinary data; distinguish it from encoding, hashing and one-time passwords.

Diagram source ↗

References