Skip to main content

14 Classical encryption algorithms

Classical encryption algorithms

Learning intention

WALT

We are learning to apply, analyse and evaluate Caesar, Vigenère, Gronsfeld and one-time pad algorithms.

WILF

  • Convert letters to numbers and use modulo 26.
  • Encrypt and decrypt with each key style.
  • Trace a well-ordered encryption algorithm.
  • Evaluate security using key space, patterns and key use.

Cognitive verbs

  • Recognise: identify facts or characteristics from what you know.
  • Analyse: break down information to reveal relationships.
  • Determine: use evidence or reasoning to reach a conclusion.
  • Develop: create a complete result by combining relevant ideas and processes.
  • Evaluate: make a judgment about quality using evidence.
  • Explain: make an idea or relationship clear by showing how or why.
 

A shared numerical model

Use the mapping A = 0, B = 1, ..., Z = 25. Addition encrypts; subtraction decrypts. Modulo 26 wraps results into the alphabet.

encrypted = (plaintext + shift) MOD 26
plaintext = (encrypted - shift + 26) MOD 26

For a shift of 5, X = 23 encrypts to (23 + 5) MOD 26 = 2, which is C.

State your convention: Cipher questions must use one consistent letter-number mapping and direction. A different stated convention may produce different intermediate numbers.

Modulo practice

Determine the encrypted letters for A, M and Z using shift 4.

Check your answer

A → E, M → Q, Z → D.

 

Caesar cipher

A Caesar cipher applies one fixed shift to every plaintext letter.

PlaintextCODE
Number21434
+3, mod 2651767
CiphertextFRGH

The ciphertext is FRGH.

Decrypt

Determine the plaintext for KHOOR with Caesar shift 3.

Check your answer

Subtracting 3 gives HELLO.

 

Evaluate Caesar security

There are only 25 useful non-zero shifts. An attacker can try them all quickly. The same plaintext letter always becomes the same ciphertext letter, so language patterns and letter frequency remain visible.

Security judgment: Caesar is useful for learning substitution and modulo arithmetic, not for protecting modern sensitive data.

 

Vigenère cipher

Vigenère repeats a keyword. Each key letter supplies a different shift using A = 0.

PlaintextCATCH
Repeated keyDOGDO
Shift3146314
CiphertextFOZFV

CATCH with key DOG becomes FOZFV.

Encrypt with Vigenère

Use key KEY to encrypt DATA. Determine the repeated key and ciphertext.

Check your answer

Repeated key: KEYK; shifts: 10, 4, 24, 10. D(3)+K(10)=N(13), A(0)+E(4)=E(4), T(19)+Y(24)=R(17), and A(0)+K(10)=K(10). The ciphertext is NERK.

 

Evaluate repeated-key security

Vigenère hides simple single-letter frequency better than Caesar because the same plaintext letter can encrypt differently at different key positions. However, a repeated keyword creates a period. With enough ciphertext, attackers can investigate repetition, infer key length and apply frequency analysis by position.

A longer keyword increases possibilities, but a predictable word and repeated use remain weaknesses.

 

Gronsfeld cipher

Gronsfeld uses a repeating sequence of decimal digits as shifts. It works like a Vigenère cipher whose shifts are limited to 0–9.

PlaintextMAPS
Key2042
CiphertextOATU

With repeating key 204, MAPS becomes OATU.

Gronsfeld varies shifts but uses only ten possible shift values and repeats the digit key, so it remains vulnerable to period and frequency analysis.

 

One-time pad

A one-time pad uses a key that is:

  • truly random
  • at least as long as the plaintext
  • kept secret
  • used once only.

Encryption can still use modular addition, but the key does not repeat. Under the required conditions, the ciphertext does not reveal a unique plaintext because every same-length plaintext has a possible key.

The conditions matter: a repeated, predictable or reused pad is not a secure one-time pad. Key generation, secure distribution and storage are major practical challenges.

Why reuse fails

Two messages use the same pad. Explain the resulting weakness.

Check your answer

Combining the two ciphertexts can cancel the shared key relationship and expose relationships between the plaintexts. Language patterns or a known part of one message can then help recover the other. Reuse removes the defining one-time condition.

 

Compare the algorithms

AlgorithmKey patternMain weakness
CaesarOne repeated shiftTiny key space and preserved frequency
VigenèreRepeated letter-key shifts 0–25Repeated period can be analysed
GronsfeldRepeated digit shifts 0–9Repeated period and restricted shifts
One-time padRandom, message-length, never reusedSecure key creation, distribution and handling
 

Develop an encryption algorithm

BEGIN
INPUT plaintext
INPUT shifts
SET ciphertext = ""
SET keyIndex = 0

FOR EACH character IN plaintext DO IF character IS A LETTER THEN SET plainNumber = LetterToNumber(UPPERCASE(character)) SET shift = shifts[keyIndex MOD LENGTH(shifts)] SET cipherNumber = (plainNumber + shift) MOD 26 SET ciphertext = ciphertext + NumberToLetter(cipherNumber) SET keyIndex = keyIndex + 1 ELSE SET ciphertext = ciphertext + character ENDIF ENDFOR

OUTPUT ciphertext END

One design choice is whether spaces and punctuation advance the key. State and apply the choice consistently. The example advances only for letters.

 

Desk check the algorithm

Use plaintext AZ! and shifts [2, 4].

CharacterKey indexShiftOutput
A02C
Z14D
!2Not used!

The output is CD!.

 

Independent practice: compare keys

Use plaintext NETWORK.

  1. Encrypt it with Caesar shift 4.
  2. Encrypt it with Vigenère key LINK.
  3. Encrypt it with Gronsfeld key 314.
  4. Analyse the repeated patterns and Evaluate relative resistance to simple brute force and frequency analysis.
View a sample solution
  1. Caesar: RIXASVO.
  2. Repeated key LINKLIN; ciphertext YMGGZZX.
  3. Repeated key 3143143; ciphertext QFXZPVN.
  4. Caesar has only 25 useful keys and one substitution alphabet, making exhaustive search and frequency analysis easy. Vigenère and Gronsfeld vary shifts, but their repeated periods can be detected. Vigenère permits 26 shift values per key position, while Gronsfeld uses only ten; actual security also depends on key length and predictability. None is appropriate for modern sensitive data.
 

Review and exit ticket

  1. Why add 26 before modulo during decryption?
  2. How do Vigenère and Gronsfeld differ?
  3. What four conditions define a one-time pad?
  4. Why is key reuse important when evaluating security?
Check your answers
  1. It avoids a negative intermediate result before wrapping.
  2. Vigenère derives shifts 0–25 from letters; Gronsfeld repeats digits 0–9.
  3. Random, secret, message-length and used once.
  4. Repeating a key creates relationships and patterns attackers can compare.

Exit ticket

Encrypt SAFE with Caesar shift 7, then state one reason the result is not secure against modern attack.