Mathwords logoMathwords

Symmetric Key — Definition, Formula & Example

A symmetric key is a single secret key that two people share and use both to lock (encrypt) and unlock (decrypt) a message. Anyone who has the key can read the messages, so the key must stay private between the sender and the receiver.

A symmetric-key encryption scheme consists of a key space K\mathcal{K}, a message space M\mathcal{M}, a ciphertext space C\mathcal{C}, and functions E:K×M→CE: \mathcal{K} \times \mathcal{M} \to \mathcal{C} and D:K×C→MD: \mathcal{K} \times \mathcal{C} \to \mathcal{M}. These functions satisfy Dk(Ek(m))=mD_k(E_k(m)) = m for every key k∈Kk \in \mathcal{K} and every message m∈Mm \in \mathcal{M}. For each fixed kk, the function EkE_k is injective, and DkD_k is its inverse on the image of EkE_k. The same kk serves both operations. Public-key schemes differ here because they use a key pair.

Key Formula

Ek(m)=(m+k) mod 26,Dk(c)=(c−k) mod 26E_k(m) = (m + k) \bmod 26, \qquad D_k(c) = (c - k) \bmod 26
Where:
  • mm = plaintext letter as a number, with A = 0, B = 1, ..., Z = 25
  • kk = the shared secret key, an integer from 0 to 25
  • cc = ciphertext letter as a number from 0 to 25
  • Ek,DkE_k, D_k = encryption and decryption functions for key k (shift cipher)

Worked Example

Problem: Alice and Bob share the secret key k=7k = 7. Alice encrypts the word MATH with the shift cipher. Then Bob decrypts the result using the same key.
Step 1: Convert each letter to a number using A = 0 through Z = 25.
M, A, T, H→12, 0, 19, 7\text{M, A, T, H} \to 12,\ 0,\ 19,\ 7
Step 2: Alice adds the key to each number and reduces mod 26. Note that 19+7=2619 + 7 = 26, which wraps around to 0.
(12+7, 0+7, 19+7, 7+7) mod 26=(19, 7, 0, 14)→THAO(12+7,\ 0+7,\ 19+7,\ 7+7) \bmod 26 = (19,\ 7,\ 0,\ 14) \to \text{THAO}
Step 3: Bob subtracts the same key and reduces mod 26. For the third letter, 0−7=−70 - 7 = -7, and −7 mod 26=19-7 \bmod 26 = 19.
(19−7, 7−7, 0−7, 14−7) mod 26=(12, 0, 19, 7)→MATH(19-7,\ 7-7,\ 0-7,\ 14-7) \bmod 26 = (12,\ 0,\ 19,\ 7) \to \text{MATH}
Answer: The ciphertext is THAO. Decrypting with the same key k=7k = 7 recovers MATH. The one shared key performs both directions.

Why It Matters

Symmetric ciphers such as AES encrypt nearly all bulk data on the internet, including HTTPS traffic and disk encryption. They are fast, but every pair of users needs its own secret key. A network of 100 people would need (1002)=4,950\binom{100}{2} = 4{,}950 keys. This key-distribution problem is why public-key methods like RSA, studied in number theory and discrete math courses, are used to exchange symmetric keys safely.

Common Mistakes

Mistake: Thinking that "symmetric" means encryption and decryption are the same operation.
Correction: The key is what is shared, not the operation. Decryption is the inverse function of encryption. In the shift cipher you add kk to encrypt and subtract kk to decrypt. Applying EkE_k twice does not undo it in general.

Related Terms