Symmetric-Key Encryption
Explain how a shared key encrypts and decrypts data with AES, and judge whether a key length and a key's storage place keep data safe.
One key that locks and unlocks
Every night at 1 am, a copy of Tulsi Health's customer database and invoices is sent to a cloud storage company as a backup. Before the copy leaves the office, Neha Kulkarni's backup software encrypts it with a secret key, and if the office ever needs the data back, the same key decrypts it. One key does both jobs. Encryption that uses the same secret key to encrypt and to decrypt is called symmetric-key encryption, or symmetric cryptography, "symmetric" because both directions mirror each other. It is the workhorse of modern security: fast, strong and used billions of times a day, from your phone's storage to the Wi-Fi in a Tulsi Health store.
Symmetric encryption works like a dabba with one lock and two copies of the same key. The lock is excellent; the hard part is getting the second key across the city without anyone copying it.
A shared secret and the everyday workflow
Picture a steel dabba with a padlock, and one key copied so that the head office in Kothrud has one copy and the Hadapsar store has the other. The office puts a price list in the dabba, locks it and sends it with any delivery boy. The delivery boy cannot open it, and neither can anyone he meets on the way. At Hadapsar, the store manager opens it with the second copy of the same key, and can send a reply back in the same locked dabba. The key that both ends hold is called a shared secret key, and as long as only those two parties have it, they can talk privately over any road at all.
The digital version follows the same encryption and decryption workflow. First, both sides get the same key, once, in advance. Then, for every message, the sender runs the plaintext and the key through the cipher and sends the ciphertext over the internet. The receiver runs the ciphertext and the same key through the cipher in reverse and gets the plaintext back. The internet, the Wi-Fi and any snooper in between see only ciphertext, just as the delivery boy sees only a locked dabba.
Step 1 happens once and must be done safely. After that, every message in either direction is locked and opened with the same key.
AES, the cipher behind most of it
The symmetric cipher you meet almost everywhere today is AES, the Advanced Encryption Standard. It was chosen in 2001 by the US government's standards body after an open competition in which cryptographers from around the world submitted designs and attacked each other's. AES works on data in small fixed-size pieces called blocks, each 128 bits, about 16 characters' worth. It mixes and substitutes each block through ten or more rounds using the key, so that every bit of the ciphertext depends on every bit of the key and the block. The result shows none of the letter patterns that made old substitution ciphers easy to read.
A bit is the smallest unit of computer data, a single 0 or 1. An AES key comes in three sizes: 128, 192 or 256 bits. A 128-bit key is a row of 128 positions, each either 0 or 1, and every extra position doubles the number of possible keys, just as adding one more dial to a number lock multiplies the combinations by ten. The design of AES is public; its strength comes entirely from the size of the key space and the quality of the mixing. Its older predecessor, DES, used 56-bit keys, and in the late 1990s a purpose-built machine found a DES key by brute force in a few days. That is why key length matters.
The short cell below counts keys for three cases: a Caesar shift, a key of three letters, and an AES-128 key, and then works out how many years a very fast computer would need to try every AES-128 key. You can press Run without knowing any Python. To experiment, change the number on the line marked "change this" and run it again.
Expected output:
Caesar keys: 25
Three-letter keys: 17,576
AES-128 keys: 340,282,366,920,938,463,463,374,607,431,768,211,456
Years to try every AES-128 key: 10,790,283,070,806,014,558,208
| Line | What it does |
|---|---|
caesar_keys = 25 |
Stores the number 25 under a name, so it can be printed later |
three_letter_keys = 26 * 26 * 26 |
26 choices for each of three letters, multiplied together: 17,576 keys |
aes_keys = 2 ** 128 |
** means "to the power of": 2 multiplied by itself 128 times, because each of 128 positions has 2 choices |
guesses_per_second = 1_000_000_000 |
100 crore guesses a second; Python lets you write underscores in a number to make it easier to read |
print(...) |
Shows a label and a value; :, adds commas to long numbers |
seconds = ... and years = ... |
Divides the number of keys by the guessing speed, then by the seconds in a year |
A three-letter key would fall in a tiny fraction of a second, while trying every AES-128 key at 100 crore guesses a second would take a 23-digit number of years, far longer than the universe has existed. Brute force is simply not how AES gets broken.
Explore the same idea with the sliders below. Choose whether a key is made of letters or bits, change its length and the attacker's computing power, and watch how quickly the time to try every key grows. The mission asks you to find a key size that holds out against a million computers for over a thousand years without being larger than needed.
The shared-key problem
Symmetric encryption has one big practical weakness, and it is not the cipher. Before the first message, both sides must already hold the same key, and that key has to get from one to the other safely. This is the key distribution problem. Imagine handing someone a dabba key across Pune, from Kothrud to Hadapsar: you could send it with a courier, but if the courier is careless, or a stranger copies the key at a tea stall on the way, every dabba ever locked with it can be opened. Sending the key by email or SMS has the same problem, because anyone reading the channel gets the key too.
The problem grows quickly with numbers. If every pair of people who want to talk privately needs their own key, two people need one key, but each new person needs a new key with everyone already there. The head office and 14 stores, 15 sites in all, would need 105 keys, and all 130 staff talking privately in pairs would need 8,385. Each of those keys has to be created, delivered safely, stored safely and replaced when someone leaves.
Each new person needs a key with everyone already there, so the count grows much faster than the number of people.
Real systems do not solve this with couriers. They use a different kind of cryptography, built on pairs of keys, to agree a fresh symmetric key safely over the open internet, and then switch to fast AES for the actual data. Inside an organisation, keys are kept in dedicated, locked-down key storage rather than in files, and replaced on a schedule.
Where symmetric encryption works every day
Because AES is fast, often built right into the processor chip, it does the heavy lifting wherever large amounts of data need protecting. Your phone encrypts its storage with a symmetric key, so a thief who pulls out the memory gets only ciphertext. Laptops can do the same for the whole disk, which matters for the 14 billing laptops at Tulsi Health store counters. Wi-Fi with a modern password scrambles the radio traffic between devices and the router using AES. Backups, database fields holding prescriptions, and the bulk of every secure website visit are all encrypted symmetrically.
Wherever there is a lot of data to protect, symmetric encryption does the work, because it is fast.
The ways it fails are almost always about the key. A key derived from a weak password such as "Tulsi@123" can be guessed far faster than a random key. A key stored next to the data it protects, in the same folder or on the same server, travels with every stolen copy. And a key that is lost means the data is lost too: if Neha's backup key disappears, the backup becomes permanent gibberish. Decide where Neha should keep the backup key in the choice below.