GHOSTNET›MODULES›MOD-03 // CRYPTOGRAPHY
← MOD-02: OSINTMOD-04: OFFENSIVE SECURITY →LAB →
MODULE 03 · CRYPTOGRAPHY

CRYPTOGRAPHY

Symmetric & asymmetric encryption · Hash functions & MACs · PKI & certificates · TLS internals · Cryptographic attacks · Post-quantum cryptography

9
CHAPTERS
~3.0hr
TOTAL READ
INTERMEDIATE
DIFFICULTY
MOD-03
IDENTIFIER
BEGINNER~18 min READCHAPTER 1 OF 9

Cryptography Fundamentals

KEY POINTS · THE QUICK VERSION
  • The four cryptographic goals are Confidentiality, Integrity, Authentication, and Non-repudiation - different algorithms serve different goals.
  • Symmetric encryption solves speed, asymmetric encryption solves key distribution - hybrid systems use both.
  • Shannon's confusion (S-boxes) and diffusion (permutations) are the two operations every strong block cipher must perform.
  • Security through obscurity is not security - Kerckhoffs's principle requires algorithms to be public and security to rest only on the key.
  • Always use a CSPRNG for key generation - regular PRNGs like rand() or math.random() are predictable and never safe for cryptographic use.
Scan these first, then read below for the depth and examples — or jump straight to the lab.

Cryptography is the science of securing communication. Before touching any algorithm, you need to understand what goals cryptography actually serves - and what it cannot do.

◈ PICTURE IT — MTAANI EDITION

When you hand your contribution to the chama committee, four things are quietly in play. You seal the cash in an envelope so only the treasurer sees it (confidentiality). The amount is written and witnessed so no one can change it later (integrity). You sign the book so they know it was really you (authentication). And because you signed, you cannot afterwards deny you gave it (non-repudiation). Cryptography chases these same four assurances.

▸ The Four Security Properties (CIA+)

Modern cryptographic systems aim to provide four core guarantees:

BEGINNER NOTE
Confidentiality - only authorised parties can read the data. Achieved via encryption.
Integrity - data has not been altered in transit. Achieved via hash functions and MACs.
Authentication - you are communicating with who you think you are. Achieved via digital signatures and certificates.
Non-repudiation - the sender cannot later deny sending a message. Achieved via digital signatures with a private key only the sender holds.

▸ Symmetric vs Asymmetric Encryption

Symmetric encryption uses the same key to encrypt and decrypt. It is fast and efficient for bulk data, but has a fundamental problem: how do you securely share the key with the other party in the first place? This is called the key distribution problem.

Asymmetric encryption uses a mathematically linked key pair - a public key (share freely) and a private key (never share). Anyone can encrypt with your public key, but only you can decrypt with your private key. This solves key distribution but is orders of magnitude slower than symmetric encryption.

In practice, hybrid encryption is used: asymmetric crypto is used to securely exchange a symmetric key, then symmetric crypto handles the actual data. TLS does exactly this.

▸ Stream Ciphers vs Block Ciphers

A block cipher encrypts fixed-size chunks of data (AES uses 128-bit blocks). Padding is added if plaintext does not fill a block. Block ciphers are used with modes of operation (CBC, GCM, CTR) to handle data larger than one block.

A stream cipher generates a pseudorandom keystream that is XORed with plaintext one bit or byte at a time. ChaCha20 and RC4 are stream ciphers. They have no padding and are naturally suited to streaming data.

▸ Substitution, Permutation, Confusion, and Diffusion

Claude Shannon (1949) identified two fundamental operations that strong ciphers must perform:

NOTE
Confusion - each bit of ciphertext should depend on several parts of the key in a complex, non-linear way. Achieved by substitution (S-boxes in AES). Makes it hard to find the key from ciphertext.

Diffusion - changing one bit of plaintext should change roughly half of the ciphertext bits. Achieved by permutation (ShiftRows, MixColumns in AES). Hides statistical structure.

▸ XOR and the One-Time Pad

XOR (exclusive or) is the fundamental operation of most ciphers. Key property: A XOR B XOR B = A. If you XOR plaintext with a random keystream and send it, the recipient XORs with the same keystream to recover the plaintext.

The one-time pad uses a truly random key the same length as the message, used only once. It is provably unbreakable - but practically useless because the key distribution problem is as hard as just sending the message securely in the first place. Reusing the key destroys security instantly.

👁 WATCH THIS · you don't need to run it yet — just read along
XOR PROPERTY DEMO
plaintext  = 0b10110100
key        = 0b01101110
ciphertext = 0b11011010  (XOR)

ciphertext = 0b11011010
key        = 0b01101110
plaintext  = 0b10110100  (XOR again to recover)
What you're seeing: This is the whole trick behind most encryption, shown in binary. Combine your message with a secret keystream using XOR and it turns to gibberish; apply the very same keystream once more and the original message comes straight back. Encrypting and decrypting are the same single move.
↪ You'll XOR bytes by hand and watch them reverse in the ↪ MOD-03 lab.

▸ Kerckhoffs Principle

A cryptographic system should be secure even if everything about the system, except the key, is public knowledge. Security through obscurity - hiding the algorithm itself - is not security. If your cipher is only safe because attackers do not know the algorithm, you have no real security.

This is why AES, ChaCha20, and RSA are all fully published. Their security comes from the mathematical hardness of the underlying problem, not from secrecy of the design.

▸ Entropy and Randomness

Cryptographic security ultimately rests on randomness. Entropy measures unpredictability in bits. A 128-bit random key has 128 bits of entropy - meaning an attacker must try 2^128 keys on average.

A CSPRNG (Cryptographically Secure Pseudo-Random Number Generator) is seeded from true entropy sources (OS noise, hardware events) and produces output that is computationally indistinguishable from true randomness. A regular PRNG (like rand() in C) is NOT safe for cryptography - its output can often be predicted after observing a few values.

WARNING
Always use the OS CSPRNG for key generation: /dev/urandom on Linux, CryptGenRandom on Windows, or high-level library functions like secrets.token_bytes() in Python. Never use math.random() or similar.

▸ Bit Security Levels

Security LevelOperations to BreakSymmetric Key SizeRSA Key SizeECC Key Size
80-bit2^80 (~1 sextillion)80-bit (obsolete)1024-bit (broken)160-bit (obsolete)
112-bit2^112112-bit2048-bit (minimum)224-bit
128-bit2^128 (currently safe)128-bit AES3072-bit256-bit (P-256)
192-bit2^192192-bit AES7680-bit384-bit (P-384)
256-bit2^256 (long-term)256-bit AES15360-bit521-bit (P-521)

▸ Cryptographic Primitives Reference

AlgorithmTypeKey SizeBlock/OutputNotes
AES-256-GCMSymmetric AEAD256-bit128-bit blockGold standard for symmetric encryption
ChaCha20-Poly1305Symmetric AEAD256-bitStreamFast without AES hardware, used in TLS 1.3
RSA-4096Asymmetric4096-bitVariableSlow, avoid for bulk data, use for key exchange
ECDH P-256Key Exchange256-bitN/AFast key agreement, 128-bit security
Ed25519Signature256-bit512-bit sigFast, deterministic, immune to k-reuse bugs
SHA-256HashN/A256-bitMerkle-Damgard construction, widely used
HMAC-SHA256MACVariable256-bitAuthenticated integrity, immune to length extension
Argon2idPassword KDFVariableVariableMemory-hard, PHC winner, use for passwords
HKDF-SHA256Key DerivationVariableVariableDerive multiple keys from one master secret
PRO TIP
Memorise this hierarchy: for bulk data encryption use AES-256-GCM or ChaCha20-Poly1305. For key exchange use ECDH. For signatures use Ed25519. For password storage use Argon2id. For everything else, use a well-audited library like libsodium and do not roll your own.
RECAP · CHECK YOURSELF
  • The four cryptographic goals are Confidentiality, Integrity, Authentication, and Non-repudiation - different algorithms serve different goals.
  • Symmetric encryption solves speed, asymmetric encryption solves key distribution - hybrid systems use both.
  • Shannon's confusion (S-boxes) and diffusion (permutations) are the two operations every strong block cipher must perform.
  • Security through obscurity is not security - Kerckhoffs's principle requires algorithms to be public and security to rest only on the key.
  • Always use a CSPRNG for key generation - regular PRNGs like rand() or math.random() are predictable and never safe for cryptographic use.
Read to the end to count this chapter
▸ READY TO PRACTISE
You've now covered enough for Lab steps 1–2 of 20. Try them in the lab while it's fresh.
OPEN LAB ▸
⚡ TEST YOURSELF
End-of-chapter quiz
A dozen questions — recall and practical. Graded, earns up to 20 XP.
PRACTISE IN THE LAB ▸
READY TO PRACTICE?
MOD-03 Interactive Lab
20 steps · 405 XP · Real commands · Flag captures
LAUNCH LAB →
← MOD-02: OSINTMOD-04: OFFENSIVE →