Cryptographic Principles

Cryptography is the study of transforming a message so that only the intended reader can recover it. Every cipher you will meet, from a simple letter shift to the schemes that protect online banking, is built from the same few parts and must satisfy the same mathematical requirement: whatever encryption does, decryption must undo. This lesson sets up that vocabulary and shows it at work in two ciphers built on arithmetic modulo 26.

The parts of a cipher

The readable message is the plaintext mm, and the scrambled version sent over an open channel is the ciphertext cc. A cipher is a family of encryption functions EkE_k and decryption functions DkD_k, one pair for each key kk in a set of allowed keys called the key space. The sender computes c=Ek(m)c = E_k(m), and the receiver, holding the matching key, computes Dk(c)D_k(c). The defining requirement is correctness:


Dk(Ek(m))=mfor every key k and every plaintext mD_k\big(E_k(m)\big) = m \quad \text{for every key } k \text{ and every plaintext } m


A direct consequence is that each EkE_k must be one-to-one. If two plaintexts encrypted to the same ciphertext, no decryption function could know which one to return.


A flow diagram in which plaintext passes through encryption with key k, travels as ciphertext over an open channel, and is decrypted with key k back to plaintext.


The design rule behind modern cryptography is Kerckhoffs's principle: a cipher should stay secure even when everything about it except the key is public. In practice you should assume the attacker knows exactly how EE and DD work and sees every ciphertext; only kk is hidden.



Shift and affine ciphers

To do arithmetic on letters, number them A = 0, B = 1, …, Z = 25 and work in Z26\mathbb{Z}_{26}. The shift cipher adds a fixed key kk:


Ek(x)=(x+k) mod 26,Dk(y)=(y−k) mod 26E_k(x) = (x + k) \bmod 26, \qquad D_k(y) = (y - k) \bmod 26


Example: With k=3k = 3, the letter H (x=7x = 7) encrypts to 10, which is K, and subtracting 3 from 10 returns 7.


The affine cipher uses a key pair (a,b)(a, b) and multiplies before shifting:


E(x)=(ax+b) mod 26,D(y)=a−1(y−b) mod 26E(x) = (ax + b) \bmod 26, \qquad D(y) = a^{-1}(y - b) \bmod 26


Here a−1a^{-1} is the multiplicative inverse of aa modulo 26, the number with a⋅a−1≡1(mod26)a \cdot a^{-1} \equiv 1 \pmod{26}. It exists exactly when aa is coprime to 26, that is, when gcd⁡(a,26)=1\gcd(a, 26) = 1. The shift cipher is the special case a=1a = 1.


Example: For the key (5,8)(5, 8), the inverse of 5 is 21, because 5⋅21=105=4⋅26+15 \cdot 21 = 105 = 4 \cdot 26 + 1. The letter C (x=2x = 2) encrypts to 5⋅2+8=185 \cdot 2 + 8 = 18, which is S. Decrypting, 21(18−8)=210=8⋅26+221(18 - 8) = 210 = 8 \cdot 26 + 2, so D(18)=2D(18) = 2 and C comes back.



Cipher

Key

Encryption

Decryption

Condition on the key

Shift

kk

(x+k) mod 26(x + k) \bmod 26

(y−k) mod 26(y - k) \bmod 26

none; 26 possible keys

Affine

(a,b)(a, b)

(ax+b) mod 26(ax + b) \bmod 26

a−1(y−b) mod 26a^{-1}(y - b) \bmod 26

gcd⁡(a,26)=1\gcd(a, 26) = 1, any bb


Symmetric and public-key schemes

Both ciphers above are symmetric: the receiver's key is the same as the sender's, or is easily computed from it, since a−1a^{-1} follows from aa in a few steps of arithmetic. A symmetric cipher therefore needs the two parties to agree on a key privately before they communicate.


A public-key scheme separates the two keys. The encryption key is published so anyone can send a message, the decryption key stays private, and recovering the private key from the public one must be computationally infeasible. The correctness requirement D(E(m))=mD(E(m)) = m still holds; only the relationship between the keys changes. RSA is the standard example and is studied on its own.

What to remember

  • Plaintext mm and key kk give ciphertext c=Ek(m)c = E_k(m); correctness means Dk(Ek(m))=mD_k(E_k(m)) = m for every key and message.
  • Each encryption function must be one-to-one, or decryption is impossible.
  • Kerckhoffs's principle: only the key is secret, so assume the method is known.
  • Shift: add kk modulo 26. Affine: ax+bax + b modulo 26, valid only when gcd⁡(a,26)=1\gcd(a, 26) = 1, decrypted with a−1a^{-1}.
  • Symmetric schemes share one key; public-key schemes publish the encryption key and keep the decryption key private.

Example: An affine cipher with key (7, 3)

Two friends agree privately to use the affine cipher E(x)=(7x+3) mod 26E(x) = (7x + 3) \bmod 26, numbering the letters A = 0, B = 1, …, Z = 25. Work each part before revealing its solution.



a) Show that (7,3)(7, 3) is a valid key and find the decryption multiplier 7−1 mod 267^{-1} \bmod 26.


The key is valid when gcd⁡(7,26)=1\gcd(7, 26) = 1, so run the Euclidean algorithm:


26=3⋅7+57=1⋅5+25=2⋅2+1\begin{aligned} 26 &= 3 \cdot 7 + 5 \\ 7 &= 1 \cdot 5 + 2 \\ 5 &= 2 \cdot 2 + 1 \end{aligned}


The last nonzero remainder is 1, so gcd⁡(7,26)=1\gcd(7, 26) = 1 and an inverse exists. Back-substitute to write 1 as a combination of 26 and 7:


1=5−2⋅2=5−2(7−5)=3⋅5−2⋅7=3(26−3⋅7)−2⋅7=3⋅26−11⋅71 = 5 - 2 \cdot 2 = 5 - 2(7 - 5) = 3 \cdot 5 - 2 \cdot 7 = 3(26 - 3 \cdot 7) - 2 \cdot 7 = 3 \cdot 26 - 11 \cdot 7


The coefficient of 7 is ________, so 7⋅(−11)≡1(mod26)7 \cdot (-11) \equiv 1 \pmod{26}. Adding 26 to bring it into the range 0 to 25 gives 7−1≡157^{-1} \equiv 15.


Check: 7 times 15 is ________, which is 4⋅26+14 \cdot 26 + 1, so the product leaves remainder 1 as required. The decryption function is D(y)=15(y−3) mod 26D(y) = 15(y - 3) \bmod 26.


b) Encrypt the word HI.


H is x=7x = 7. Multiplying and shifting, 7 · 7 + 3 = ________, and 52=2⋅2652 = 2 \cdot 26, so E(7)=0E(7) = 0, which is A.


I is x=8x = 8. Here 7 · 8 + 3 = ________, and 59−2⋅26=759 - 2 \cdot 26 = 7, so E(8)=7E(8) = 7, which is H.


The ciphertext is AH. Notice that the plaintext letter H and the ciphertext letter H are unrelated positions; an affine cipher moves each letter independently.


c) The receiver gets the ciphertext QX. Decrypt it.


Use D(y)=15(y−3) mod 26D(y) = 15(y - 3) \bmod 26 from part a.


Q is y=16y = 16. Then y−3=13y - 3 = 13, and 15 · 13 = ________. Since 7⋅26=1827 \cdot 26 = 182, 195−182=13195 - 182 = 13, which is N.


X is y=23y = 23. Then y−3=20y - 3 = 20, and 15 · 20 = ________. Since 11⋅26=28611 \cdot 26 = 286, 300−286=14300 - 286 = 14, which is O.


The plaintext is NO. Check by encrypting N: 7⋅13+3=94=3⋅26+167 \cdot 13 + 3 = 94 = 3 \cdot 26 + 16, which is Q, matching the first ciphertext letter.



Match each cryptography term with the description that fits it. Every description refers to protecting a message sent between two people, and each description is used exactly once.

Match each term
A.

The map that recovers the readable message from the scrambled output

B.

The secret value that selects one transformation from a family

C.

The scrambled output that travels over an open channel

D.

The original readable message before any transformation

E.

Sender and receiver use the same secret value, or values easily derived from each other

F.

Security should depend on a secret parameter alone, never on hiding the method

Decryption function

Symmetric scheme

Plaintext

Kerckhoffs's principle

Ciphertext

Key

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Two people want to exchange a private message using an affine cipher with the 26-letter alphabet coded as A = 0, B = 1, …, Z = 25 and a shared secret key (a,b)(a, b), where gcd⁡(a,26)=1\gcd(a,26)=1. Put the stages of the exchange in the order they must happen, from first to last.

  1. 1.

    The sender converts the results to letters and transmits the ciphertext.

  2. 2.

    The sender and receiver agree on the key (a,b)(a, b) over a secure channel.

  3. 3.

    The sender converts each plaintext letter to a number xx from 0 to 25 and computes y=(ax+b) mod 26y = (ax + b) \bmod 26 using the agreed key.

  4. 4.

    The receiver converts the recovered numbers to letters to read the plaintext.

  5. 5.

    The receiver converts each received ciphertext letter to a number yy and computes x=a−1(y−b) mod 26x = a^{-1}(y - b) \bmod 26.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

An affine cipher numbers the letters A = 0 through Z = 25 and encrypts each letter by E(x)=(ax+4) mod 26E(x) = (ax + 4) \bmod 26. Which choice of the multiplier aa gives a key that the intended receiver can always decrypt correctly?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice