Privacy note: We capture your IP address to provide customised and focused services. See our Privacy Policy.

Cybersecurity Essentials — Alpha School

Lesson 9: Cryptography Basics: Ciphers, Keys and Kerckhoffs's Principle

Cryptography is the science of keeping messages secret, and it is older than computers by thousands of years: generals, diplomats and lovers have been scrambling messages for as long as there have been messages worth stealing. The core idea has barely changed: a cipher is a method for turning readable text, called plaintext, into scrambled text, called ciphertext, using a key, and only someone with the right key can turn it back. What has changed is the maths, which is now strong enough that a well-designed cipher cannot be broken by any computer that exists, and the rules for designing ciphers, which are the subject of this lesson. Understanding those rules is the foundation for the next three lessons, on symmetric and asymmetric encryption and on TLS.

Ciphers, keys and the Caesar shift

The simplest cipher is the Caesar cipher, named for Julius Caesar, who is said to have used it for military messages. Each letter is shifted by a fixed number of places: with a shift of three, A becomes D, B becomes E, and so on, so the word HELLO becomes KHOOR. The shift is the key, and anyone who knows it can reverse the message, while anyone who does not must try all twenty-five possible shifts, which takes seconds, so the Caesar cipher is a teaching tool, not a real defence. Its value is in showing the pattern every cipher follows: an algorithm, which is public and fixed, plus a key, which is secret and changeable, and the security lives in the key, not in keeping the algorithm secret, which brings us to the most important principle in cryptography.

Kerckhoffs's principle

In the nineteenth century, the Dutch cryptographer Auguste Kerckhoffs wrote down a rule that still governs all serious cryptography: a system should remain secure even if everything about it, except the key, is public. That means the algorithm can be published, studied and attacked by the world's best mathematicians, and it should still hold, because its strength comes from the key, which is the only secret. The opposite approach, called security through obscurity, hiding how a system works and hoping nobody figures it out, always fails eventually, because secrets leak, and once the method is known, there is nothing left to protect. This principle is why the ciphers you will meet in this course, such as AES, are public standards, tested by thousands of experts, and why you should never trust a cipher whose designer says “the algorithm is secret”, because that secrecy is usually hiding weakness, not strength.

What makes a cipher strong

A strong cipher has three properties. First, its key space, the number of possible keys, must be so large that trying them all is impossible: a key of 128 bits has about 340 billion billion billion billion possible values, far beyond any computer's reach, which is why modern keys are at least 128 bits long. Second, it must resist clever attacks, not just brute force, so a cipher that is secure only if the attacker tries keys one by one is not secure at all, and serious ciphers are tested for years before anyone trusts them. Third, it must be used correctly, because a strong cipher with a weak key, a reused key, or a flawed implementation is still breakable, and most real-world failures are failures of use, not of maths. That is why this course spends as much time on keys, how they are made, shared and stored, as on the ciphers themselves.

Cryptography is not just secrecy

Beginners often think cryptography is only about keeping messages secret, but it does three other jobs that matter just as much. It provides integrity, proving a message has not been altered, through tools such as message authentication codes, which you will meet in Lesson 10. It provides authentication, proving who a message came from, through digital signatures, which you will meet in Lesson 11. And it provides non-repudiation, meaning the sender cannot later deny sending it, which matters for contracts and legal evidence. When you use the web, all four jobs are happening at once: TLS encrypts your data, checks it has not been altered, proves the server is who it claims to be, and does so in a way the server cannot deny. Keeping those jobs separate in your mind will make the next three lessons much clearer.

Key Terms

Cryptography
The science of keeping messages secret and proving they are genuine and unaltered.
Cipher
A method for turning plaintext into ciphertext, and back, using a key.
Plaintext / ciphertext
Plaintext is readable text; ciphertext is the scrambled output of a cipher.
Key
A secret value that controls a cipher; the security lives in the key, not in the algorithm.
Kerckhoffs's principle
A system should stay secure even if everything about it, except the key, is public.
Key space
The number of possible keys; a large key space makes trying them all impossible.
Security through obscurity
Hiding how a system works and hoping nobody figures it out; it always fails eventually.

Discussion Questions

  1. Why is it safer for a cipher's algorithm to be public than secret?
  2. The Caesar cipher has only 25 possible keys. Why does that make it useless as a real defence?
  3. How would you explain Kerckhoffs's principle to a friend who thinks secrecy is the same as security?

Practice Questions

  1. Using a Caesar shift of three, what does HELLO become?
  2. What is the difference between a cipher and a key?
  3. What does Kerckhoffs's principle say?
  4. Why is a large key space important?
  5. Name two jobs cryptography does besides keeping messages secret.
Show answers
  1. KHOOR. Each letter moves three places forward: H becomes K, E becomes H, L becomes O, and O becomes R.
  2. A cipher is the method; a key is the secret value that controls it. The same cipher with different keys produces different ciphertext.
  3. A system should stay secure even if everything except the key is public. The algorithm can be known to everyone, and the security must come from the key alone.
  4. Because it makes trying every key impossible. A 128-bit key has so many possible values that no computer could try them all.
  5. Any two, such as integrity (proving a message was not altered), authentication (proving who sent it), or non-repudiation (the sender cannot deny sending it).
Keep reading to complete this lesson