Cryptography Basics
Overview — The first of three introductory cryptography rooms on TryHackMe and a Fundamentals primer. It defines the core vocabulary (plaintext, ciphertext, cipher, key), shows why cryptography matters in everyday traffic, breaks the Caesar cipher by brute force, compares symmetric (DES, 3DES, AES) and asymmetric (RSA, Diffie-Hellman, ECC) encryption, and introduces the two bits of maths behind many algorithms: XOR and modulo.
| Platform | TryHackMe |
| Category | Fundamentals |
| Difficulty | Easy |
| Room | Cryptography Basics |
Task 1 — Introduction
Cryptography is what lets two parties who have never met talk over an untrusted network and still be sure that nobody read or changed the data, and that they are talking to the right peer. Networking connects the devices; cryptography makes the conversation trustworthy. This room is the first in a series (followed by public-key cryptography and hashing) and requires only basic command-line comfort. Topics: key terms, why cryptography matters, the Caesar cipher, standard symmetric and asymmetric ciphers, and basic maths.
Task 2 — Importance of Cryptography
Cryptography is the study and practice of secure communication in the presence of adversaries. It protects three properties:
- Confidentiality: only intended parties can read the data.
- Integrity: any tampering is detectable.
- Authenticity: you know who sent it or which server you are talking to.
You rely on it constantly: logging in to a website over HTTPS, an SSH session, a bank's certificate proving that your browser reached the real bank, and a hash that confirms a download matches the original. Industry regulation exists too: organisations that handle payment cards must follow the Payment Card Industry Data Security Standard.
Q: What is the standard required for handling credit card information?
A: PCI DSS
Task 3 — Plaintext to Ciphertext
The vocabulary used throughout cryptography:
| Term | Meaning |
|---|---|
| Plaintext | The original readable data: text, an image, a database, any binary content. |
| Ciphertext | The scrambled output. A good cipher leaks nothing about the plaintext except roughly its size. |
| Cipher | The algorithm that converts plaintext to ciphertext and back. |
| Key | The secret input (a string of bits) that parameterises the cipher. |
| Encryption / decryption | Applying the cipher with the key in the forward / reverse direction. |
A guiding principle (Kerckhoffs's principle): the cipher itself is assumed to be public, and all security rests on the key staying secret. Algorithms hidden behind obscurity tend to fail once someone reverse engineers them.
Q: What do you call the encrypted plaintext?
A: Ciphertext
Q: What do you call the process that returns the plaintext?
A: Decryption
Task 4 — Historical Ciphers
The Caesar cipher (first century BCE) replaces every letter with the one a fixed number of places further along the alphabet, wrapping from Z back to A. With key 3, TRYHACKME becomes WUBKDFNPH (T to W, R to U, Y to B, and so on). To decrypt, shift left by the same amount.
The weakness is the tiny key space. A shift of 26 returns the original text, so there are only 25 useful keys, and an attacker simply tries all of them. Even with no computer, that is a few minutes of work. Other historical ciphers worth reading about are Vigenère (16th century), the Enigma machine (World War II) and the one-time pad (Cold War), the only one of the three that is provably unbreakable when used correctly.
The challenge ciphertext can be broken with an online tool or a short script that tries every shift:
ct = "XRPCTCRGNEI"
for k in range(26):
print(k, "".join(chr((ord(c) - 65 - k) % 26 + 65) for c in ct))
Only one line is readable English: shift 15 gives the answer. The BSD caesar utility (echo XRPCTCRGNEI | caesar) does the same by frequency analysis.
Q: Knowing that XRPCTCRGNEI was encrypted using Caesar Cipher, what is the original plaintext?
A: ICANENCRYPT
Task 5 — Types of Encryption
Symmetric encryption
One shared secret key both encrypts and decrypts. It is fast and well suited to bulk data, but the hard part is key distribution: if you email an encrypted document and its password through the same channel, anyone who reads that mailbox gets both. The key has to travel over a separate secure channel, which becomes harder with every additional recipient.
| Cipher | Introduced | Key size | Status |
|---|---|---|---|
| DES | 1977 standard | 56 bits | Broken: a key was recovered in under 24 hours in 1999. Do not use. |
| 3DES | Stop-gap for DES | 168-bit key, about 112 bits effective | Deprecated (NIST, 2019); only found in legacy systems. |
| AES | 2001 standard | 128, 192 or 256 bits | The current standard. |
Asymmetric encryption
Two mathematically linked keys are used: a public key, shared freely, and a private key, kept secret. Data encrypted with the public key can only be decrypted with the private key, so two strangers can set up secrecy without first sharing a secret. Examples: RSA, Diffie-Hellman (a key-exchange protocol) and elliptic curve cryptography (ECC).
Security rests on problems that are easy in one direction and infeasible to reverse (for RSA, multiplying large primes versus factoring the product). The price is speed and size: RSA needs 2048-bit keys at minimum (3072 or 4096 for more margin), and Diffie-Hellman similar. ECC reaches comparable strength with far shorter keys; a 256-bit ECC key is roughly comparable to a 3072-bit RSA key. In practice systems combine the two: asymmetric cryptography to agree on a key, symmetric cryptography to protect the data (this is how TLS works).
Alice and Bob are the conventional fictional parties in every example.
Q: Should you trust DES? (Yea/Nay)
A: Nay
Q: When was AES adopted as an encryption standard?
A: 2001
Task 6 — Basic Math
XOR
XOR (exclusive OR, written ⊕ or ^) outputs 1 when its two input bits differ:
| A | B | A ⊕ B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Applied bit by bit, 1010 ⊕ 1100 = 0110. Three properties make it useful: A ⊕ A = 0, A ⊕ 0 = A, and it is commutative and associative. Together they give a working toy cipher. With plaintext P and key K, the ciphertext is C = P ⊕ K, and applying the key again recovers the plaintext:
C ⊕ K = (P ⊕ K) ⊕ K = P ⊕ (K ⊕ K) = P ⊕ 0 = P
The same operation encrypts and decrypts. Real use needs a key as long as the message; a truly random key used once is the one-time pad, while a short key that repeats is easy to break. XOR is also a building block inside modern ciphers such as AES-based stream modes.
Q: What's 1001 ⊕ 1010?
A: 0011
Modulo
The modulo operation X % Y is the remainder after dividing X by Y, and it always lies between 0 and Y-1. Examples: 25 % 5 = 0, 23 % 6 = 5 (23 = 3 × 6 + 5), 23 % 7 = 2. It cannot be undone: x % 5 = 4 is satisfied by infinitely many x. That one-way, wrap-around behaviour is exactly what asymmetric algorithms like RSA and Diffie-Hellman exploit. For big numbers use a language with arbitrary-precision integers; Python is ideal:
python3 -c "print(118613842 % 9091)"
python3 -c "print(60 % 12)"
3565
0
Q: What's 118613842 % 9091?
A: 3565
Q: What's 60 % 12?
A: 0
Key takeaways
- Cryptography provides confidentiality, integrity and authenticity; the cipher is public and only the key is secret.
- A small key space (Caesar has 25 keys) means brute force wins instantly; DES with 56 bits fell for the same reason on a larger scale.
- Use AES for symmetric encryption; treat DES and 3DES as legacy to be replaced.
- Symmetric encryption is fast but has a key-distribution problem; asymmetric solves distribution but is slower, so real protocols combine both.
- XOR (self-inverse) and modulo (one-way) are the maths that keep reappearing, from stream ciphers to RSA.