📘 CodingMarble Learn

Cryptography: How Secret Messages Keep Data Safe

Cryptography is the science of keeping messages secret and trustworthy. A normal message (plaintext) is mixed with a key to make a secret message (ciphertext); this is encryption. Turning it back with the right key is decryption. Old ciphers like the Caesar cipher shift letters. Modern systems use symmetric encryption (one shared key) and asymmetric or public-key encryption (a public key to lock, a private key to unlock). Hashing makes a fixed-length fingerprint of data to check it was not changed, and digital signatures prove who sent a message. Your phone uses all of these every time you open a website with https or send a chat message.

🎬 Step-by-step story

  1. Plaintext is your normal message. A key changes it into ciphertext, which looks like nonsense.
  2. The Caesar cipher moves every letter forward by the key. With key 3, HELLO becomes KHOOR.
  3. In symmetric encryption both people use the same key to lock and unlock.
  4. In public-key encryption anyone can lock with the public key, but only the private key unlocks.
  5. A hash makes a short fingerprint. Change one letter and the fingerprint changes completely.
  6. Try it: move the shift slider and type a word. Watch the wheel turn and the cipher change.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

If the cipher looks like nonsense, how does the receiver read it?

The receiver knows the key and runs the steps backwards (decryption).

What happens after Z in a Caesar cipher?

It wraps round to A, like a wheel. That is why we use mod 26.

Why not just use one shared key for everything?

You still have to send that key safely first. If someone steals it on the way, they can read everything.

If everyone has my public key, can't they read my messages?

No. The public key can only lock. Opening needs the private key, which only you have.

Is hashing a kind of encryption?

No. Encryption can be undone with a key; a hash is one-way and only checks if data changed.

What does a shift of 13 do twice?

13 + 13 = 26, a full turn, so you get the original word back.

What is cryptography?

Cryptography means "secret writing". It keeps information safe from people who should not read or change it.

Cryptography helps with four goals: confidentiality (only the right people read it), integrity (nobody changed it), authentication (you know who sent it) and non-repudiation (the sender cannot deny sending it).

Classic ciphers: Caesar and substitution

In a Caesar cipher every letter moves forward a fixed number of places. With key 3: A→D, B→E, … X→A, Y→B, Z→C (it wraps round).

A substitution cipher swaps each letter for another letter using a table. A transposition cipher keeps the letters but changes their order.

These are easy to break. A Caesar cipher has only 25 useful keys, so a computer can try all of them (a brute-force attack). Letter counts also give it away: E is the most common letter in English, so the most common cipher letter is probably E (frequency analysis).

Symmetric and asymmetric (public-key) encryption

Symmetric

One shared secret key both encrypts and decrypts. It is fast, so it is used for large data (for example AES). Problem: how do you send the key safely?

Asymmetric (public-key)

Each person has a key pair: a public key that anyone may have and a private key kept secret. Data locked with the public key can be opened only with the matching private key (for example RSA). It solves the key-sharing problem but is slower.

Real systems such as https use both: public-key cryptography to agree on a secret key, then symmetric encryption for the data.

Hashing, digital signatures and authentication

A hash function turns any data into a short fixed-length value. The same input always gives the same hash, a tiny change gives a totally different hash, and you cannot get the input back. Websites store password hashes, not passwords.

A digital signature: the sender hashes the message and locks the hash with their private key. Anyone can check it with the sender's public key. This proves who sent it and that it was not changed.

Authentication means proving who you are: something you know (password), have (phone OTP) or are (fingerprint). Using two of these is two-factor authentication.

Key formulas and definitions

Worked examples

1. Encrypt CAT with a Caesar shift of 4.

C(2)+4=6 → G; A(0)+4=4 → E; T(19)+4=23 → X. Answer: GEX.

2. Decrypt the Caesar cipher BQQMF, key 1.

Move each letter 1 back: B→A, Q→P, Q→P, M→L, F→E. Answer: APPLE.

3. Encrypt ZOO with key 3 (watch the wrap).

Z(25)+3=28, 28 mod 26 = 2 → C; O(14)+3=17 → R; O → R. Answer: CRR.

4. Riya wants anyone to send her secret files, but only she should open them. Which keys are used?

Senders lock the file with Riya's public key. Only Riya's private key can unlock it. She never shares the private key.

5. Why is a Caesar cipher weak?

It has only 25 useful keys. A computer can try all 25 in a moment, and letter frequencies also reveal the shift.

Common mistakes

Practice quiz

1. The readable original message is called:
2. In a Caesar cipher with key 2, the letter Y becomes:
3. Symmetric encryption uses:
4. Which key must be kept secret?
5. A good hash function:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is cryptography in simple words?

It is the science of turning messages into secret code with a key so only the right people can read them, and of checking that data was not changed.

What is the difference between encryption and hashing?

Encryption can be reversed with the key. Hashing is one-way: it makes a fixed fingerprint used to check data and store passwords.

What are public and private keys?

A matched pair. The public key is shared and used to lock or verify; the private key is secret and used to unlock or sign.

Where this is taught

PolandLiceum ogólnokształcące, klasa IVLaw and safety
South Korea고등학교 2학년Data
Russia10 классDigital literacy

Learn first

Learn next

Related lessons

All Computer Science lessons