Encryption Protects Stored Files
What encryption is, the words for its parts (plaintext, key, ciphertext, keyspace), and the two ways to classify algorithms: one key or two, block or stream.
1Why encrypt a file
The purpose of cryptography is to hide information. A stolen laptop, a lost USB drive, or a copied backup exposes every file on it, unless those files are encrypted. Encryption hides the information; decryption reverses the encryption to get the original back. A cryptographic algorithm defines the process for both.
2Plaintext, key, ciphertext
An encryption algorithm combines the information to be encrypted with a key. The input is the plaintext; the output is the ciphertext. Here is a very simple algorithm, shifting every letter forward in the alphabet by the key:
| Part | Value | Role |
|---|---|---|
| Plaintext | MEET AT NOON | The readable information to protect |
| Algorithm | Shift each letter forward | The public process; everyone may know it |
| Key | 7 | The secret value that controls the result |
| Ciphertext | TLLA HA UVVU | The scrambled output that is safe to store |
Shifting back by 7 recovers MEET AT NOON. The algorithm can be public; the security comes from keeping the key secret.
3Keyspace
The number of possible keys an algorithm can use is its keyspace. The larger the keyspace, the longer it takes an adversary to find the right key by trying them. The shift cipher has only 25 useful keys, so trying all of them takes seconds by hand:
key 1: SKKZ GZ TUUT
key 2: RJJY FY STTS
key 3: QIIX EX RSSR
key 4: PHHW DW QRRQ
key 5: OGGV CV PQQP
key 6: NFFU BU OPPO
key 7: MEET AT NOON ← readable
key 8: LDDS ZS MNNM
key 9: KCCR YR LMML
...
key 25: UMMB IB VWWV
Real algorithms use binary keys. Each extra bit doubles the keyspace. At a trillion guesses per second:
| Key length | Keyspace | Time to try every key |
|---|---|---|
| 8 bits | 28 = 256 | less than a second |
| 40 bits | 240 = 1,099,511,627,776 | about 1 second |
| 56 bits | 256 = 72,057,594,037,927,936 | about 1 day |
| 128 bits | 2128 = about 3.4 × 1038 | about 1.1 × 1019 years |
| 256 bits | 2256 = about 1.2 × 1077 | about 3.7 × 1057 years |
A 56-bit key falls in about 1 day at that speed; a 128-bit key would outlast the universe many times over.
4Symmetric and asymmetric
Algorithms are classified by whether they use one key or two:
- Symmetric algorithms use the same key to encrypt and decrypt. Anyone who can decrypt can also encrypt.
- Asymmetric algorithms use two different keys: one to encrypt and the other to decrypt.
5Block and stream
Algorithms are also classified by how they move through the information:
- Block encryption handles information in fixed-size chunks called blocks, producing one output block for each input block.
- Stream encryption handles input continuously, producing output one element at a time.
A block cipher with 16-character blocks would split the 34-character message Rehearsal moved to Room 214, 4 PM. like this:
| Block | Contents | Characters |
|---|---|---|
| 1 | Rehearsal moved | 16 |
| 2 | to Room 214, 4 P | 16 |
| 3 | M. | 2 |
The last block has only 2 characters, so 14 characters of padding fill it to full size before it is encrypted. A stream cipher needs no padding; it encrypts each character as it arrives, which suits live data such as a phone call.
Encryption combines plaintext with a key to produce ciphertext, and decryption reverses it. A larger keyspace means a longer search for the key. Symmetric algorithms use one key, asymmetric use two; block ciphers work in fixed chunks, stream ciphers one element at a time.
6Worked examples
The locked report
A nurse saves visit-notes.txt as visit-notes.enc using an app and a secret key. Name the plaintext, the ciphertext, and what someone needs to read the notes again.
- 1Plaintext: the readable
visit-notes.txt. - 2Ciphertext: the scrambled
visit-notes.enc. - 3To decrypt, a person needs the algorithm (known) and the key (secret).
Two more bits
Cipher A uses 40-bit keys. Cipher B uses 42-bit keys. How many times longer does it take to try every key for B?
- 1Each extra bit doubles the keyspace.
- 2Two extra bits: 2 × 2 = 4.
- 3242 ÷ 240 = 4.
One key or two? Block or stream?
An algorithm encrypts data 128 bits at a time, and the same key that encrypts a file also decrypts it. Classify it both ways.
- 1The same key encrypts and decrypts: symmetric.
- 2It works on fixed 128-bit chunks: block.
The lost USB drive
A club's USB drive with member phone numbers is lost. The file on it was encrypted with a strong key that is not stored on the drive. What can the finder learn?
- 1The finder has the ciphertext only.
- 2Without the key, they must try keys; a strong key's keyspace makes that take far too long.
- 3The phone numbers stay hidden.
7Common mistakes
Strong algorithms are public. The key is what must stay secret.
Each bit doubles it. 128 bits is not twice as strong as 64 bits; it is 264 times larger.
Symmetric or asymmetric is about the number of keys. Block or stream is about how data is processed. An algorithm has one of each label.
“Encrypting the file combines its plaintext with a secret key to produce ciphertext. Someone who steals the file sees only the ciphertext, and with a 128-bit key the keyspace is so large that trying every key is not practical.”
Name the plaintext, the key, and the ciphertext, and connect the key length to how hard the key is to find.