Cryptography Basics

Introduction
Cryptography lays the foundation for our digital world. While networking protocols have made it possible for devices spread across the globe to communicate, cryptography has made it possible to trust this communication.
Importance of Cryptography
Cryptography is the science of protecting data so that only authorized people can read or change it, even when attackers are present. It ensures:
Confidentiality (keeping data private)
Integrity (making sure data isn't changed)
Authenticity (verifying who sent the data)
You use cryptography all the time:
Logging in to websites (your credentials are encrypted)
Using SSH (your session is encrypted)
Online banking (secure connection with the bank)
File downloads (hashes confirm file integrity)
What is the standard required for handling credit card information?
Answer: PCI DSS
Plaintext to Ciphertext
Plaintext is the original, readable message or data before it’s encrypted. It can be a document, an image, a multimedia file, or any other binary data.
Ciphertext is the scrambled, unreadable version of the message after encryption. Ideally, we cannot get any information about the original plaintext except its approximate size.
Cipher is an algorithm or method to convert plaintext into ciphertext and back again. A cipher is usually developed by a mathematician.
Key is a string of bits the cipher uses to encrypt or decrypt data. In general, the used cipher is public knowledge; however, the key must remain secret unless it is the public key in asymmetric encryption. We will visit asymmetric encryption in a later task.
Encryption is the process of converting plaintext into ciphertext using a cipher and a key. Unlike the key, the choice of the cipher is disclosed.
Decryption is the reverse process of encryption, converting ciphertext back into plaintext using a cipher and a key. Although the cipher would be public knowledge, recovering the plaintext without knowledge of the key should be impossible (infeasible).
What do you call the encrypted plaintext?
Answer:ciphertext.
What do you call the process that returns the plaintext?
Answer:Decryption.
Historical Ciphers
Cryptography’s history is long and dates back to ancient Egypt in 1900 BCE. However, one of the simplest historical ciphers is the Caesar Cipher from the first century BCE. The idea is simple: shift each letter by a certain number to encrypt the message.
Consider the following example:
Plaintext:
TRYHACKME
Key: 3 (Assume it is a right shift of 3.)
Cipher: Caesar Cipher
We can easily figure out that T becomes W, R becomes U, Y becomes B, and so on. As you noticed, once we reach Z, we start all over, as shown in the figure below. Consequently, we get the ciphertext of WUBKDFNPH
.
o decrypt, we need the following information:
Ciphertext:
WUBKDFNPH
Key: 3
Cipher: Caesar Cipher
For encryption, we shift to the right by three; for decryption, we shift to the left by three and recover the original plaintext, as illustrated in the image above. However, if someone gives you a ciphertext and tells you that it was encrypted using Caesar Cipher, recovering the original text would be a trivial task as there are only 25 possible keys. The English alphabet is 26 letters, and shifting by 26 will keep the letter unchanged; hence, 25 valid keys for encryption with Caesar Cipher. The figure below shows how decryption will succeed by attempting all the possible keys; in this case, we recovered the original message with Key = 5. Consequently, by today’s standards, where the cipher is publicly known, Caesar Cipher is considered insecure.
Knowing that XRPCTCRGNEI
was encrypted using Caesar Cipher, what is the original plaintext?Question Hint
You can use an online tool such as the ones available at https://cryptii.com/pipes/caesar-cipher and https://www.dcode.fr/caesar-cipher
Answer:ICANENCRYPT
Types of Encryption
Symmetric Encryption
Symmetric encryption is a method where the same key is used to both:
Encrypt (lock) the data
Decrypt (unlock) the data
Think of it like a padlock where one key locks and unlocks a box. If both you and your friend have a copy of that same key, you can securely exchange secret messages.
Examples of symmetric encryption are DES (Data Encryption Standard), 3DES (Triple DES) and AES (Advanced Encryption Standard).
DES was adopted as a standard in 1977 and uses a 56-bit key. With the advancement in computing power, in 1999, a DES key was successfully broken in less than 24 hours, motivating the shift to 3DES.
3DES is DES applied three times; consequently, the key size is 168 bits, though the effective security is 112 bits. 3DES was more of an ad-hoc solution when DES was no longer considered secure. 3DES was deprecated in 2019 and should be replaced by AES; however, it may still be found in some legacy systems.
AES was adopted as a standard in 2001. Its key size can be 128, 192, or 256 bits.
Example:
Let’s say you want to send a secret message to your friend:
You write:
Hello
You use a secret key to scramble it into gibberish (ciphertext):
X7sG1!@
Your friend gets the scrambled message and uses the same key to turn it back into
Hello
.
The big challenge with symmetric encryption is keeping the key safe:
You and your friend must share the key without anyone else seeing it.
If you're sending the key over the internet, someone could steal it.
If many people need the key, it's harder to keep it secret.
A hacker, spy, or competitor (called an adversary) could try to steal the key — and then read all your secret messages.
Asymmetric Encryption
Unlike symmetric encryption (which uses one secret key), asymmetric encryption uses two keys:
A public key to encrypt the data
A private key to decrypt the data
This method is also called public key cryptography.
How It Works
You share your public key with anyone.
Someone uses your public key to encrypt a message.
Only you can decrypt it using your private key, which you keep secret.
🔑 Public key locks, private key unlocks.
Examples of Asymmetric Encryption:
RSA
Diffie-Hellman
Elliptic Curve Cryptography (ECC)
Performance
Asymmetric encryption is slower than symmetric.
It uses larger keys for strong security.
RSA: 2048-bit or more
ECC: Much shorter keys (e.g. 256-bit ECC ≈ 3072-bit RSA)
Why It’s Secure
Asymmetric encryption is based on math problems that are:
Easy to solve one way
Extremely hard to reverse (even for powerful computers)
Should you trust DES? (Yea/Nay)
Answer: Nay
When was AES adopted as an encryption standard?
Answer: 2001
XOR Operation
XOR, short for “exclusive OR”, is a logical operation in binary arithmetic that plays a crucial role in various computing and cryptographic applications. In binary, XOR compares two bits and returns 1 if the bits are different and 0 if they are the same, as shown in the truth table below. This operation is often represented by the symbol ⊕ or ^.
A | B | A ⊕ B |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Modulo Operation
Another mathematical operation we often encounter in cryptography is the modulo operator, commonly written as % or as mod. The modulo operator, X%Y, is the remainder when X is divided by Y. In our daily life calculations, we focus more on the result of division than on the remainder. The remainder plays a significant role in cryptography.
You need to work with large numbers when solving some cryptography exercises. If your calculator fails, we suggest using a programming language such as Python. Python has a built-in int
type that can handle integers of arbitrary size and would automatically switch to larger types as needed. Many other programming languages have dedicated libraries for big integers. If you prefer to do your math online, consider WolframAlpha.
Let’s consider a few examples.
25%5 = 0 because 25 divided by 5 is 5, with a remainder of 0, i.e., 25 = 5 × 5 + 0
23%6 = 5 because 23 divided by 6 is 3, with a remainder of 5, i.e., 23 = 3 × 6 + 5
23%7 = 2 because 23 divided by 7 is 3 with a remainder of 2, i.e., 23 = 3 × 7 + 2
An important thing to remember about modulo is that it’s not reversible. If we are given the equation x%5 = 4, infinite values of x would satisfy this equation.
The modulo operation always returns a non-negative result less than the divisor. This means that for any integer a and positive integer n, the result of a%n will always be in the range 0 to n − 1.
What’s 1001 ⊕ 1010?
Answer:0011
What’s 118613842%9091?
Answer:3565
What’s 60%12?
Answer:0
Cryptography Overview
Cryptography is the science of protecting data from unauthorized access. It ensures:
Confidentiality – Only the right people can read the data.
Integrity – The data hasn’t been changed.
Authenticity – The sender is who they say they are.
We use cryptography daily in things like website logins, online banking, SSH sessions, and file verification.
Symmetric Encryption
Uses one key for both encryption and decryption.
Fast and efficient.
Problem: The key must be shared secretly with others, which is risky.
Also called private key encryption.
Example: AES
"Same key to lock and unlock."
Asymmetric Encryption
Uses two keys:
A public key to encrypt.
A private key to decrypt.
No need to secretly share keys.
Slower, but more secure for key exchange.
Also called public key cryptography.
Examples: RSA, ECC, Diffie-Hellman
"Public key locks, private key unlocks."
Symmetric vs Asymmetric (Quick Table)
Feature | Symmetric | Asymmetric |
Keys | One key (shared) | Two keys (public/private) |
Speed | Fast | Slower |
Use Case | Data encryption | Secure key exchange, signatures |
Key Size | Small (128–256 bits) | Large (2048+ RSA / 256 ECC) |
Examples | AES | RSA, ECC, DH |
Subscribe to my newsletter
Read articles from MD MUNIF MUBTASHIM directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

MD MUNIF MUBTASHIM
MD MUNIF MUBTASHIM
CSE student | Cybersecurity Learner | Red Team Path | Blogging my CTF & hacking journey .