Vernam Cipher Examples & Tutorials

Learn how to use One-Time Pad encryption with practical examples

1. Basic Encryption Examples

Example 1: Basic Encryption

Message: HELLO
Key: XMCKL
Result: EQNVZ

Simple five-letter example showing Vigenere mode encryption

Example 2: Complete Tutorial

Message: ATTACKATDAWN
Key: XJHREOWKGFLM
Result: XCARGYWDJFHZ

Longer one-time pad example with matching key length

Example 3: Military Communication

Message: MEET AT BRIDGE
Key: VICTORYVICTOR
Result: HMGM OK ZMQFZS

Historical military-style message

2. Step-by-Step Tutorial (Vigenere Mode)

Step 1

Step 1: Convert Letters to Numbers

Each letter is assigned a number from 0-25 (A=0, B=1, ..., Z=25)

H = 7, E = 4, L = 11, L = 11, O = 14 X = 23, M = 12, C = 2, K = 10, L = 11
Step 2

Step 2: Add Corresponding Values

Add plaintext and key values, then take modulo 26 to stay within alphabet

(7 + 23) mod 26 = 30 mod 26 = 4 = E (4 + 12) mod 26 = 16 = Q (11 + 2) mod 26 = 13 = N (11 + 10) mod 26 = 21 = V (14 + 11) mod 26 = 25 = Z
Step 3

Step 3: Result

The encrypted message is mathematically unbreakable without the key

Final ciphertext: EQNVZ

3. XOR Mode Example

Understanding XOR Operation

XOR (exclusive OR) is a binary operation where the output is 1 only when inputs differ.

Input A
Input B
A XOR B
0
0
0
0
1
1
1
0
1
1
1
0

Binary Example

Binary message: 01001000 (H)
Binary key: 10110111
XOR result: 11111111 (ÿ)

4. Historical Case: Cold War OTP

During the Cold War, Soviet agents and diplomats used one-time pads extensively for secure communications. These pads were small booklets containing pages of random numbers or letters. Each page would be used once for a single message and then destroyed.

The Venona Project: When Soviet agents reused keys during WWII, American cryptanalysts were able to decrypt thousands of messages, compromising major spy networks. This demonstrates why key reuse is catastrophic.

5. Common Mistakes to Avoid

❌ Mistake 1: Reusing a Key

If you use the same key for two different messages, attackers can XOR the ciphertexts together to eliminate the key and reveal information about both plaintexts.

Example: Venona Project broke Soviet communications by exploiting reused keys.

❌ Mistake 2: Using Non-random Keys

Using dictionary words or patterns as keys makes the cipher vulnerable to dictionary attacks and statistical analysis.

Always use cryptographically secure random number generators.

❌ Mistake 3: Key Shorter Than Message

If the key is shorter than the message and repeats, it becomes a Vigenère cipher which is vulnerable to cryptanalysis.

Key length must equal or exceed message length for perfect secrecy.

Learning the Vernam Cipher becomes clear and intuitive when you work through practical examples. This page provides comprehensive vernam cipher example demonstrations ranging from basic encryption to advanced historical case studies. Each one-time pad example includes detailed step-by-step calculations, helping you understand both the mathematics and the security principles behind this theoretically unbreakable cipher. Whether you're a cryptography student, a history enthusiast, or simply curious about perfect secrecy, these vernam cipher tutorial materials will guide you from beginner to confident practitioner.

Our examples progress systematically from simple demonstrations to complex real-world scenarios. You'll see basic vernam cipher encryption and decryption, complete tutorials walking through every calculation, XOR mode demonstrations, historical case studies from the Cold War era, and critical lessons about common mistakes that compromise security. Each one-time pad cipher example can be loaded directly into our online tools, allowing you to verify calculations and experiment with variations. This hands-on approach helps you truly understand how to work out vernam cipher operations and why proper key management is absolutely essential.

Example 1 - Basic Vernam Cipher Encryption (Vigenere Mode)

The Scenario

Let's start with the simplest possible vernam cipher example to understand the fundamental encryption process. We'll encrypt the message "HELLO" using the random key "XMCKL" in Vigenere Mode. This basic one-time pad example demonstrates letter-to-number conversion, modular addition, and the encryption algorithm in its most straightforward form. While real one-time pad applications use longer keys and messages, this compact example makes it easy to follow every step of the calculation.

Step-by-Step Encryption Process

Step 1: Convert Letters to Numbers

The first step in any vernam cipher encryption is converting letters to their numerical equivalents. We use the standard mapping: A=0, B=1, C=2, continuing through Z=25. This gives us a consistent way to perform mathematical operations on letters.

  • Plaintext HELLO converts to: H=7, E=4, L=11, L=11, O=14
  • Key XMCKL converts to: X=23, M=12, C=2, K=10, L=11

This letter to number conversion is the foundation of the Vigenere-mode vernam cipher example. Each letter position gets its own unique key letter, which is why the key must be at least as long as the message.

Step 2: Add Corresponding Values

Now we add each plaintext number to its corresponding key number. This is where the actual encryption happens in our one-time pad example:

  • H + X = 7 + 23 = 30
  • E + M = 4 + 12 = 16
  • L + C = 11 + 2 = 13
  • L + K = 11 + 10 = 21
  • O + L = 14 + 11 = 25

Notice that the first calculation (7 + 23 = 30) produces a number larger than 25. This is where modulo arithmetic becomes essential in the next step.

Step 3: Apply Modulo 26

To keep our results within the 26-letter alphabet, we apply modulo 26 to each sum. This wraps any number greater than 25 back into the 0-25 range:

  • 30 mod 26 = 4 = E
  • 16 mod 26 = 16 = Q
  • 13 mod 26 = 13 = N
  • 21 mod 26 = 21 = V
  • 25 mod 26 = 25 = Z

Our final ciphertext is EQNVZ. This vernam cipher example shows how plaintext "HELLO" becomes completely transformed into ciphertext that reveals no information about the original message when the key is truly random.

Step 4: Verification

To verify this vernam cipher encryption and decryption example, we can reverse the process. Decryption subtracts the key values: E(4) - X(23) = -19 mod 26 = 7 = H, and so forth, returning us to "HELLO". This demonstrates the mathematical symmetry of the one-time pad cipher example.

Try This Example

Load this example directly into our Vernam Cipher Encoder to see the encryption in action. Try modifying the message or key to observe how changes affect the ciphertext. This hands-on experimentation helps solidify your understanding of how to work out vernam cipher operations.

Example 2 - Complete Tutorial with Encryption and Decryption

The Message

For this comprehensive vernam cipher tutorial, we'll encrypt a longer, more realistic message: "ATTACKATDAWN" (the famous military command). First, we remove spaces and convert everything to uppercase, giving us 12 characters to encrypt. This one-time pad example demonstrates the complete workflow from plaintext to ciphertext and back to plaintext, showing both encryption and decryption phases of the vernam cipher encryption and decryption process.

Generating a Random Key

A critical part of any vernam cipher example is key generation. For "ATTACKATDAWN" (12 letters), we need a key of at least 12 letters. Let's use the random key: "XJHREOWKGFLM". In real one-time pad applications, this key would be generated using a cryptographically secure random number generator, not chosen by hand. The randomness of the key is what provides the mathematical guarantee of perfect secrecy.

Each letter of our key must be truly random and unpredictable. If our key had patterns or was based on a dictionary word, we would compromise the security of this vernam cipher example, turning it into a breakable cipher similar to the Vigenere cipher.

Encryption Process

Let's encrypt "ATTACKATDAWN" with key "XJHREOWKGFLM" step by step. This vernam cipher encryption example shows the complete calculation:

PlaintextP ValueKeyK ValueSumMod 26Ciphertext
A0X232323X
T19J9282C
T19H7260A
A0R171717R
C2E466G
K10O142424Y
A0W222222W
T19K10293D
D3G699J
A0F555F
W22L11337H
N13M122525Z

The encrypted ciphertext is XCARGYWD JFHZ. This one-time pad cipher example shows how a meaningful message transforms into seemingly random letters. Without the key "XJHREOWKGFLM", determining that this ciphertext decrypts to "ATTACKATDAWN" is mathematically impossible.

Decryption Process

Now let's decrypt "XCARGYWDJFHZ" back to the original message using the same key "XJHREOWKGFLM". The vernam cipher encryption and decryption process uses subtraction with modulo 26:

CiphertextC ValueKeyK ValueC - KMod 26Plaintext
X23X2300A
C2J9-719T
A0H7-719T
R17R1700A
G6E422C
Y24O141010K
W22W2200A
D3K10-719T
J9G633D
F5F500A
H7L11-422W
Z25M121313N

The decrypted plaintext is ATTACKATDAWN – perfect verification! Notice how negative values in the "C - K" column are correctly handled by modulo 26 to produce the right plaintext letters.

Key Takeaways

This complete vernam cipher tutorial demonstrates several critical points: encryption and decryption are exact mathematical inverses; the key must be exactly the same length or longer than the message; modulo arithmetic correctly handles values outside the 0-25 range; and the ciphertext appears completely random and reveals no information about the plaintext. You can practice this vernam cipher example on our encoder and decoder pages.

Example 3 - XOR Mode Encryption

Understanding XOR Operation

Before diving into our XOR-based vernam cipher example, let's understand the XOR (exclusive OR) operation. XOR is a binary operation that returns 1 when the two input bits are different, and 0 when they're the same. Here's the XOR truth table:

  • 0 XOR 0 = 0 (same bits = 0)
  • 0 XOR 1 = 1 (different bits = 1)
  • 1 XOR 0 = 1 (different bits = 1)
  • 1 XOR 1 = 0 (same bits = 0)

The beautiful property of XOR encryption is its symmetry: applying XOR twice with the same key returns the original value. This makes XOR perfect for one-time pad example demonstrations, as encryption and decryption use the identical operation. This is why many modern implementations of the vernam cipher use XOR mode.

Binary Encryption Example

Let's encrypt the letter 'H' using XOR in this one-time pad cipher example. First, we convert 'H' to its binary representation using ASCII: H = 72 in decimal = 01001000 in binary.

Next, we need a random key byte. Let's use the random binary key: 10110111

Now we perform the XOR operation bit by bit:

Plaintext:  01001000  (H)
Key:        10110111  (random)
            --------  XOR operation
Ciphertext: 11111111  (255 in decimal)

The encrypted result is the binary value 11111111. To verify the XOR encryption worked correctly, we decrypt by applying XOR again with the same key:

Ciphertext: 11111111
Key:        10110111  (same key)
            --------  XOR operation
Plaintext:  01001000  (H recovered!)

This vernam cipher example shows XOR's self-reversing property – the same operation encrypts and decrypts.

Complete Word Example

Let's encrypt a full word "HELLO" using XOR mode in this vernam cipher tutorial. Each letter converts to 8 bits:

H = 01001000  →  XOR with key byte 10110111 = 11111111
E = 01000101  →  XOR with key byte 00101101 = 01101000
L = 01001100  →  XOR with key byte 11110001 = 10111101
L = 01001100  →  XOR with key byte 01011110 = 00010010
O = 01001111  →  XOR with key byte 10001100 = 11000011

The resulting ciphertext bytes (in binary) are: 11111111 01101000 10111101 00010010 11000011

This XOR-based vernam cipher encryption and decryption example demonstrates how binary operations provide efficient, secure encryption. Modern computer systems handle XOR operations extremely quickly, making this an excellent choice for practical one-time pad implementations.

Try It Yourself

Visit our Vernam Cipher Encoder and select XOR Mode to experiment with binary encryption. The tool handles all binary conversions automatically while showing you the encrypted results. This hands-on practice helps you master XOR mode encryption.

Example 4 - Historical Case Study: Cold War One-Time Pad

Soviet Spy Communications

One of the most fascinating one-time pad examples comes from Cold War espionage. Soviet intelligence agencies, particularly the KGB, relied heavily on one-time pad systems for communicating with their agents in foreign countries. Soviet agents carried small booklets containing pages of random numbers – physical one-time pads. Each page provided the key material for encrypting a single message, after which the agent would tear out and destroy the used page.

This historical vernam cipher example shows the practical implementation of perfect secrecy in real-world espionage. An agent receiving instructions from Moscow would use the appropriate page from their OTP booklet to decrypt the message. The Moscow headquarters kept identical booklets, ensuring both sender and receiver had matching keys. This system provided absolute security for Soviet intelligence communications – messages intercepted by American or British intelligence were completely unreadable without the physical one-time pad booklets.

The physical key distribution was handled through diplomatic pouches, dead drops, and courier services – secure channels that prevented interception of the key material. This real one-time pad cipher example demonstrates both the strength of the system (unbreakable encryption) and its main weakness (the logistical challenge of physically distributing key material to agents worldwide). Despite these challenges, the security guarantee made it worth the effort for the most sensitive communications.

The Venona Project - When OTP Was "Broken"

The Venona Project represents the most famous case of "breaking" the one-time pad – but it's crucial to understand this wasn't a flaw in the vernam cipher example methodology. During World War II, the Soviet Union faced severe shortages of key material due to the pressures of wartime. Rather than compromise operational security by halting communications, they made a fatal decision: they reused some one-time pad keys. This key reuse transformed their theoretically unbreakable cipher into a vulnerable one.

American and British cryptanalysts at the Venona Project discovered this key reuse in the late 1940s. When the same key encrypts two different messages, analysts can XOR the two ciphertexts together, eliminating the key from the equation and revealing the XOR of the two plaintexts. This mathematical property allowed the codebreakers to use statistical analysis, language patterns, and cribs (known plaintext fragments) to decrypt portions of the Soviet intelligence messages. Over several decades, the Venona Project decrypted approximately 3,000 messages, exposing numerous Soviet spy networks in the United States and Britain.

This historical one-time pad example teaches a critical lesson: the Vernam Cipher was not "broken" in the cryptographic sense. The encryption algorithm remained sound. What failed was human adherence to the key management rules. This vernam cipher tutorial demonstrates why security protocols emphasize key discipline: use each key only once, ensure true randomness, and maintain key length requirements. The Venona Project succeeded not because the one-time pad is weak, but because improper use destroyed its security properties. When used correctly, as in many other Soviet communications that remain undecrypted to this day, the one-time pad kept secrets perfectly.

Example 5 - Common Mistakes and Why They're Dangerous

Mistake 1 - Reusing a Key

Let's demonstrate with a concrete vernam cipher example why key reuse is catastrophic. Suppose we encrypt two messages with the same key:

Message 1: "HELLO"  +  Key: "XMCKL"  =  Ciphertext 1: "EQNVZ"
Message 2: "WORLD"  +  Key: "XMCKL"  =  Ciphertext 2: "TYEPP"

This breaks the fundamental rule of one-time pad security. An attacker who intercepts both ciphertexts can XOR them together:

EQNVZ XOR TYEPP = (Result contains XOR of HELLO and WORLD)

The XOR operation eliminates the key, leaving only the XOR of the two plaintexts. Using frequency analysis, common word patterns, and statistical methods, a skilled cryptanalyst can recover both original messages without ever determining the key. This vulnerability is exactly how the Venona Project succeeded.

The lesson from this one-time pad cipher example is absolute: never, ever reuse a key. Each message requires its own unique, random key. Even reusing a single character of a key compromises that position in both messages. This is why the system is called a "one-time" pad – the key is literally for one-time use only.

Mistake 2 - Using a Non-Random Key

Another dangerous mistake is using a non-random key. Let's see why with this vernam cipher example. Suppose someone uses the word "SECRET" as their key:

Message: "ATTACK"
Key:     "SECRET"
Result:  "SSGVIV"

At first glance, this looks like it worked – we got ciphertext. But this key is not random; it's a dictionary word with patterns and biases. The letter frequency distribution in "SECRET" doesn't match the uniform distribution required for perfect secrecy. An attacker can exploit this non-randomness.

Furthermore, if an attacker guesses or discovers that dictionary words are being used as keys, they can try common words as potential keys. The key space shrinks from 26^6 random combinations to the much smaller number of English words of length 6. This vulnerability transforms your vernam cipher encryption into something more like a Vigenere cipher – breakable through frequency analysis and dictionary attacks.

True one-time pad security requires cryptographically secure random number generation. Use tools like our Key Generator that employ the browser's Crypto API to ensure genuine randomness. Never use passwords, dictionary words, names, dates, or any patterned sequence as keys.

Mistake 3 - Using a Short Key

The third critical mistake in this one-time pad example is using a key shorter than the message. Suppose we have:

Message: "ATTACKATDAWN" (12 letters)
Key:     "SECRET"       (6 letters - too short!)

When the key runs out, you have two bad choices: either truncate your message to 6 letters (losing information) or repeat the key. Most people repeat the key:

Message: "ATTACKATDAWN"
Key:     "SECRETSECRET" (repeated)

This transforms your one-time pad into a repeating-key cipher, essentially a Vigenere cipher with a 6-letter keyword. The security is completely lost. Cryptanalysts can use Kasiski examination to identify the key length, then solve each position independently using frequency analysis.

The key length requirement is absolute in any proper vernam cipher tutorial: keys must be at least as long as the message, preferably longer. If you need to encrypt a 1000-character message, generate a 1000-character key. There are no shortcuts that maintain security. Short keys don't provide one-time pad security; they provide Vigenere-level security, which is easily broken with modern tools.

Practice Exercises

Test your understanding with these vernam cipher example exercises. Try solving them on paper first, then verify your answers using our online tools.

Exercise 1: Simple Encryption

Problem: Encrypt the message "CAT" using the key "DOG" in Vigenere mode.

Hint: Convert letters to numbers (C=2, A=0, T=19 and D=3, O=14, G=6), add them with modulo 26, and convert back.

Your Turn: Work through this one-time pad example before revealing the answer below.

Show Answer
C (2) + D (3) = 5 mod 26 = 5 = F
A (0) + O (14) = 14 mod 26 = 14 = O
T (19) + G (6) = 25 mod 26 = 25 = Z

Answer: "FOZ"

Exercise 2: Decryption Practice

Problem: Decrypt the ciphertext "EQNVZ" using the key "XMCKL" in Vigenere mode.

Hint: This is the reverse of encryption – subtract key values from ciphertext values with modulo 26.

Your Turn: Solve this vernam cipher encryption and decryption example step by step.

Show Answer
E (4) - X (23) = -19 mod 26 = 7 = H
Q (16) - M (12) = 4 mod 26 = 4 = E
N (13) - C (2) = 11 mod 26 = 11 = L
V (21) - K (10) = 11 mod 26 = 11 = L
Z (25) - L (11) = 14 mod 26 = 14 = O

Answer: "HELLO"

Exercise 3: XOR Mode Challenge

Problem: Encrypt the binary byte 00110011 with the key byte 11001100 using XOR.

Hint: Apply XOR bit by bit: 0 XOR 1 = 1, 1 XOR 1 = 0, etc.

Your Turn: Work through this binary one-time pad cipher example.

Show Answer
Plaintext:  00110011
Key:        11001100
            --------  XOR
Ciphertext: 11111111

To verify, XOR again:
11111111 XOR 11001100 = 00110011 ✓

Frequently Asked Questions

How to work out a Vernam cipher?

To work out a vernam cipher, follow this systematic process: First, convert both your plaintext and key to numbers using A=0, B=1, through Z=25. Second, add each plaintext number to its corresponding key number. Third, apply modulo 26 to each result to keep values in the 0-25 range. Finally, convert the resulting numbers back to letters for your ciphertext. For example, in this vernam cipher example: H(7) + X(23) = 30 mod 26 = 4 = E.

This vernam cipher tutorial shows the Vigenere mode process. For XOR mode, convert letters to binary and apply XOR bit-by-bit instead of addition. Practice with the examples above, especially Example 1 for basic encryption and Example 2 for complete encryption and decryption. For hands-on learning, visit our Vernam Cipher Encoder to experiment with different messages and keys, verifying your manual calculations against the automated results.

Can you show a one-time pad cipher example?

Yes! Example 1 above demonstrates a basic one-time pad cipher example: encrypting "HELLO" with key "XMCKL" to produce ciphertext "EQNVZ". For a more comprehensive example, see Example 2, which shows the complete encryption of "ATTACKATDAWN" with detailed step-by-step calculations and a table showing every mathematical operation. That vernam cipher example also includes the decryption process, showing how to recover the original message from the ciphertext.

For even more examples, Example 3 demonstrates XOR mode encryption with binary operations, Example 4 presents historical Cold War use cases showing real-world one-time pad applications, and Example 5 illustrates common mistakes to avoid. Each one-time pad example can be tried in our online tools – just click the "Try This Example" links to load the example values into the encoder or decoder. This hands-on approach is the best way to learn how to work out vernam cipher operations.

How to solve a one-time pad cipher?

To solve (decrypt) a one-time pad cipher, you absolutely must have the original encryption key – there is no way to "solve" it without the key due to perfect secrecy. If you have the key, the vernam cipher encryption and decryption process is straightforward: convert the ciphertext and key to numbers, subtract the key values from the ciphertext values, apply modulo 26 to handle negative numbers correctly, and convert back to letters.

See Example 2's decryption section for a detailed one-time pad example showing this process. The table demonstrates every step: X(23) - X(23) = 0 = A, C(2) - J(9) = -7 mod 26 = 19 = T, and so on, recovering "ATTACKATDAWN" from the ciphertext. Try practicing with our Vernam Cipher Decoder – enter a ciphertext and its key to see the decryption. Remember: without the key, solving a properly-implemented one-time pad is mathematically impossible, not just difficult.

What happens if you reuse a one-time pad key?

Reusing a one-time pad key completely destroys the security of the cipher, as demonstrated in Example 5 Mistake 1. When the same key encrypts two messages, an attacker can XOR the two ciphertexts together, eliminating the key and revealing the XOR of the two plaintexts. This enables powerful cryptanalysis that can recover both original messages without ever knowing the key. The famous Venona Project, detailed in Example 4, successfully decrypted Soviet intelligence messages precisely because keys were reused during World War II due to wartime shortages.

This is the most critical mistake in any vernam cipher example – never reuse keys. The one-time pad's perfect secrecy depends absolutely on single-use keys. Even reusing a small portion of a key compromises those character positions in both messages. After encrypting with a key, that key must be securely destroyed and never used again for any other message. Read Example 4's Venona Project section to understand the historical consequences of key reuse, and see Example 5 for a mathematical demonstration of why key reuse breaks the cipher.

Ready to Try It Yourself?

Now that you've worked through these comprehensive vernam cipher examples and one-time pad tutorials, you're ready to experiment with the actual encryption tools. All the examples on this page can be recreated and modified using our online vernam cipher calculator and decoder. Understanding these examples transforms abstract concepts into practical knowledge.

Start Encrypting – Visit our Vernam Cipher Encoder to encrypt your own messages. Try recreating Example 1 or Example 2 to verify your understanding, then experiment with your own messages and keys.

Try Decrypting – Practice decryption at our Vernam Cipher Decoder page. Use the ciphertext from any example above with its corresponding key to see the decryption process in action.

Generate Keys – Create truly random, cryptographically secure keys with our One-Time Pad Key Generator. Remember the lessons from Example 5 about key quality – always use proper random keys, never dictionary words or patterns.

The vernam cipher encryption and decryption process becomes intuitive through practice. These one-time pad cipher examples provide the foundation; hands-on experimentation with the tools cements your understanding. Explore, experiment, and learn why Gilbert Vernam's invention remains the only provably unbreakable cipher in cryptographic history.