AI Computer Institute
Expert-curated CS & AI curriculum aligned to CBSE standards. A bharath.ai initiative. About Us

Encryption

📚 Technology⏱️ 25 min read🎓 Grade 8
✍️ AI Computer Institute Editorial Team Updated: August 2026 CBSE-aligned · Peer-reviewed · 25 min read
Content curated by subject matter experts with IIT/NIT backgrounds. All chapters are fact-checked against official CBSE/NCERT syllabi.

Imagine you are at a busy railway station, waiting for your train, and you open the IRCTC app on the station's free public Wi-Fi to check your PNR status and pay a small cancellation fee. Dozens of other people are connected to that same Wi-Fi network. Somewhere among them could be someone running a simple piece of software that "listens" to every bit of data flowing over that network — a technique called packet sniffing. If your password and card details travelled over that Wi-Fi as plain, readable text, that listener would read them exactly as easily as you did. This is not a hypothetical horror story; it is the default situation for any data sent over a network with no protection at all. Encryption is the branch of computer science that stops this from happening, and it is one of the few ideas in your CS syllabus that you personally rely on dozens of times a day, usually without noticing.

What Encryption Actually Does

Strip away the jargon and encryption is a very old idea applied with modern mathematics: take a message that anyone could read, and transform it — using a secret piece of information — into a message that looks like meaningless noise to everyone except the person who is supposed to read it. Computer science gives precise names to each part of this process, and you should learn to use them exactly, because CBSE questions are often lost or won on precise vocabulary:

  • Plaintext — the original, readable message. Example: INDIA.
  • Ciphertext — the scrambled, unreadable output. Example: LQGLD.
  • Key — the secret value that controls exactly how the scrambling happens. Without the correct key, you cannot reverse the process.
  • Cipher (or algorithm) — the fixed set of rules or steps that combines the plaintext and the key to produce ciphertext. The cipher itself is usually public knowledge; only the key is secret.
  • Encryption — running the cipher forward: plaintext + key → ciphertext.
  • Decryption — running the cipher backward: ciphertext + key → plaintext, recovering the original message.

Mathematically, we write encryption as a function E that takes a key k and a message m and produces ciphertext c: Ek(m) = c. Decryption is the inverse function D, and for a correctly designed cipher, Dk(Ek(m)) = m — that is, decrypting an encrypted message with the right key always gives you back exactly what you started with. This one-line definition is the entire contract that any encryption scheme, from a 2000-year-old military cipher to the system protecting your bank's app right now, must satisfy.

A crucial rule, first stated clearly in the 1880s by the cryptographer Auguste Kerckhoffs and still the foundation of the entire field today, is this: a cipher's security should depend only on the secrecy of the key, never on the secrecy of the algorithm. Real systems like the ones protecting Indian banking apps publish their exact algorithms for anyone in the world to study. What stays secret is only the key. This matters because an algorithm is hard to change once millions of devices use it, but a key can be replaced instantly if it leaks.

A Cipher You Can Compute By Hand: The Caesar Shift

The cleanest way to understand the plaintext-key-ciphertext relationship is to build the simplest possible cipher yourself, one that Julius Caesar reportedly used to protect military messages roughly 2000 years ago. The idea: pick a number k between 1 and 25, called the shift. To encrypt, replace every letter of the plaintext with the letter that sits k positions later in the alphabet, wrapping back to 'A' after 'Z'.

Let's actually do this. Take the plaintext INDIA and a key of k = 3. First, number the alphabet from 0 to 25, so A = 0, B = 1, C = 2, ..., Z = 25. Now shift each letter of INDIA forward by 3 positions:

  • I is letter number 8. 8 + 3 = 11, which is L.
  • N is letter number 13. 13 + 3 = 16, which is Q.
  • D is letter number 3. 3 + 3 = 6, which is G.
  • I is letter number 8 again. 8 + 3 = 11, which is L.
  • A is letter number 0. 0 + 3 = 3, which is D.

So INDIA encrypts to LQGLD. Notice the wraparound rule matters for letters near the end of the alphabet: if you were shifting the letter X (position 23) by 3, you would compute 23 + 3 = 26, which is one past Z, so it wraps around to A (position 0). This "wrap around after 26" behaviour is exactly what the modulo operation (remainder after division) does for you in one step: new position = (old position + shift) mod 26, where "mod 26" means "take the remainder when you divide by 26." Since 26 mod 26 = 0, the formula automatically sends X + 3 = 26 back to position 0, which is A. This is the same remainder idea you already use when you compute what day of the week it will be 40 days from today by working modulo 7.

Here is that exact formula as working Python code, which encrypts and decrypts using the same shift-based idea:

def caesar_encrypt(text, shift):
    result = ""
    for ch in text:
        if ch.isalpha():
            base = ord('A') if ch.isupper() else ord('a')
            position = ord(ch) - base
            new_position = (position + shift) % 26
            result += chr(new_position + base)
        else:
            result += ch  # spaces, digits, punctuation pass through unchanged
    return result

def caesar_decrypt(text, shift):
    return caesar_encrypt(text, -shift)   # decrypting is just shifting backward

print(caesar_encrypt("INDIA", 3))   # LQGLD
print(caesar_decrypt("LQGLD", 3))   # INDIA

Trace the first call by hand to confirm it matches our manual work: ord('I') is 73, ord('A') is 65, so position = 73 - 65 = 8. new_position = (8 + 3) % 26 = 11. chr(11 + 65) = chr(76), and character 76 in ASCII is 'L'. That matches. The decrypt call works because shifting by -shift and taking % 26 in Python correctly wraps negative numbers back into the range 0–25 (Python's % always returns a non-negative result for a positive divisor), so caesar_decrypt("LQGLD", 3) shifts every letter back by 3 and recovers INDIA exactly, satisfying the Dk(Ek(m)) = m contract from the previous section.

The diagram below shows this exact transformation visually — each plaintext letter moving three steps forward to become its ciphertext letter:

Caesar cipher: key = +3 I N D I A plaintext shift each letter +3 (mod 26) L Q G L D ciphertext

Why "Simple" Is Not the Same as "Safe"

A Caesar cipher has exactly 25 usable keys (a shift of 0 does nothing, so it is not really a key). That means an attacker who has intercepted your ciphertext does not even need to be clever — they can simply try all 25 shifts by hand in a few minutes, or write four lines of code to try all 25 in microseconds, and read off the one shift that produces readable words. This is called a brute-force attack: trying every possible key until one works. The number of possible keys is called the key space, and the entire strength of a cipher against brute force depends on that key space being too large to search, not on the cipher being clever or complicated.

Even without brute force, Caesar ciphers fall to a second, older attack called frequency analysis. In any long piece of normal English text, the letter E appears far more often than any other letter, followed by T, A, and O. If you intercept a long enough Caesar-encrypted message, whichever ciphertext letter appears most often is very likely the encryption of E, and that single guess tells you the shift immediately. A cipher that only rearranges letters one-to-one, without changing how often each symbol appears, leaks its own statistical fingerprint. This is precisely why real ciphers used today do not simply shift letters; they mix bits in ways designed so that ciphertext is statistically indistinguishable from random noise, destroying any such fingerprint.

To see why key space size matters so much, compare two numbers. Caesar's key space is 25. The modern symmetric cipher used inside HTTPS connections and most password managers, called AES with a 128-bit key, has a key space of 2128. You can estimate how enormous this is using a trick worth knowing: 210 = 1024, which is close enough to 1000 = 103 to use as an approximation. So 2128 = 2120 × 28 = (210)12 × 256 ≈ (103)12 × 256 = 1036 × 256, which is on the order of 1038. The exact value of 2128 is 340,282,366,920,938,463,463,374,607,431,768,211,456 — about 3.4 × 1038 keys, matching our estimate. A computer trying a billion keys every second would still need vastly longer than the current age of the universe to search even a small fraction of that space. This is the difference between a cipher a human can break by hand in a coffee break and one that entire government agencies, using the fastest computers on Earth, cannot brute-force.

Misconception Corner: Encoding Is Not Encryption

A mistake students make constantly, including in professional software, is confusing encryption with encoding. You may have seen Base64, a scheme that turns text or images into strings made of letters, digits, and symbols like SGVsbG8=. This looks scrambled and "secure," but it is not encryption at all — it uses no key, and anyone in the world can reverse it instantly using a standard, publicly known table with no secret information whatsoever. Base64 exists purely to make binary data safe to transmit through systems (like old email protocols) that only understand plain text; it provides zero confidentiality. If an app claims to "encrypt" your data but the transformation uses no secret key at all, it has not encrypted anything — it has only encoded it, and anyone can undo that step. Genuine encryption always requires a secret key that only the intended parties possess.

The Real Bottleneck: How Do You Share the Key?

Caesar's cipher and AES both share one property: the same key is used to encrypt and to decrypt. This is called symmetric-key encryption, and it works well once both sides already possess the shared secret key. But think carefully about your IRCTC app opening a secure connection to IRCTC's server for the very first time. Your phone and IRCTC's server have never met before and share no secret. If they tried to agree on a symmetric key by sending it to each other in the open, over that same public railway-station Wi-Fi, the packet-sniffing attacker from our opening scenario would simply read the key off the wire and then decrypt everything afterward. Symmetric encryption alone cannot solve this "first contact" problem — you cannot securely establish a shared secret using a channel that is not yet secure. This is called the key distribution problem, and for decades it was considered a fundamental limitation of cryptography.

Public-Key Encryption: The Padlock That Anyone Can Close

The breakthrough that solved this, developed independently in the 1970s and now underlying essentially all secure communication on the internet, is asymmetric-key encryption (also called public-key encryption). Instead of one shared secret key, every user generates a mathematically linked pair of keys: a public key, which they publish openly for the whole world to see, and a private key, which they keep completely secret and never share with anyone.

The everyday analogy that makes this click: imagine an open padlock that anyone can snap shut, but that can only be opened again with one specific key that never leaves your pocket. IRCTC's server publishes its open padlock (its public key) to anyone who connects. Your phone puts your card details in a box, snaps IRCTC's padlock shut on it (encrypts using IRCTC's public key), and sends the locked box across the network. Even the packet-sniffing attacker who captures this locked box cannot open it — they only have the padlock (the public key), not the one private key that opens it, which sits only on IRCTC's server. This single idea directly solves the key distribution problem: the public key can be shouted across an insecure network in the clear, because possessing it only lets you lock things, never unlock them.

The mathematics that makes this padlock trick actually work (the most famous version is called RSA, published in 1977) relies on modular exponentiation — raising numbers to a power and then taking the remainder after dividing by some fixed number. Real RSA uses keys built from prime numbers hundreds of digits long, far beyond hand calculation, but the exact same arithmetic works with tiny numbers, which lets us trace it completely by hand as a toy example (never used for real security, only for understanding the mechanism):

Let n = 33 and suppose (through the RSA key-generation process, which we won't derive here) the public key is the pair (e = 3, n = 33) and the matching private key is (d = 7, n = 33). Say the secret message is the single number m = 4.

Encrypt using the public key: c = me mod n = 43 mod 33 = 64 mod 33 = 31. So the ciphertext is 31.

Decrypt using the private key: m = cd mod n = 317 mod 33. Rather than multiplying 31 by itself seven times (a huge number), we compute it step by step, squaring and reducing modulo 33 at each stage:

# Verifying the toy RSA example in Python
n = 33
e, d = 3, 7
m = 4

c = pow(m, e, n)      # encrypt with public key (e, n)
print(c)              # 31

recovered = pow(c, d, n)   # decrypt with private key (d, n)
print(recovered)           # 4  -- matches the original message

Tracing the decryption by hand confirms the code: 312 = 961, and 961 mod 33 = 4 (since 33 × 29 = 957, remainder 4). So 312 ≡ 4 (mod 33). Then 314 = (312)2 ≡ 42 = 16 (mod 33). Now 317 = 314 × 312 × 311 ≡ 16 × 4 × 31 (mod 33). Compute 16 × 4 = 64, and 64 mod 33 = 31. Then 31 × 31 = 961, and 961 mod 33 = 4, exactly as before. So 317 ≡ 4 (mod 33) — we recover m = 4, the original message, using only the private key d = 7. Anyone who intercepted the ciphertext 31 and only knows the public key (e = 3, n = 33) is stuck: reversing this step without knowing d requires factoring n back into its original two prime numbers, which is fast for our toy n = 33 (it's 3 × 11) but becomes computationally infeasible when n is built from two 150-digit primes, exactly the way key-space size made brute force infeasible for AES.

The diagram below shows the full round trip using the padlock analogy:

Public-key (asymmetric) encryption Your phone plaintext: card no. lock with server's PUBLIC key ciphertext travels openly unlock with server's PRIVATE key IRCTC server recovers plaintext An eavesdropper who copies the ciphertext in transit still cannot read it — only the private key, which never leaves the server, can unlock it.

One more detail worth knowing, because it explains why your apps feel fast: asymmetric encryption is computationally much slower than symmetric encryption, because modular exponentiation with huge numbers takes far more processor work than AES's simpler bit-mixing. So real systems like HTTPS use a hybrid approach: they use asymmetric encryption only once, briefly, to safely exchange a fresh symmetric key over the insecure network (exactly solving the key distribution problem from the previous section), and then switch to fast symmetric encryption, using that freshly shared key, for the actual bulk of the data — your PNR details, your payment, your chat messages. This is why the small padlock icon appears the instant you open a banking site: your browser and the server have just finished this public-key handshake before a single rupee of information changes hands.

Misconception Corner: Encryption Is Not the Same as Hashing

Students frequently mix up encryption with a related but fundamentally different tool: hashing. Encryption is reversible by design — the whole point is that the intended recipient can decrypt the ciphertext back into the original plaintext using a key. Hashing is deliberately one-way: a hash function takes an input of any size and produces a fixed-size fingerprint, but there is no key and no way to run it backward to recover the input, even for the person who created the hash. This is exactly why, when IRCTC or your bank stores your password, they do not "encrypt" it (which would imply someone could decrypt it back to plain text) — they store a hash of it, and check your login by hashing what you type and comparing fingerprints. If their database is ever stolen, an encrypted password could theoretically be decrypted by whoever holds the key, but a properly hashed password cannot be reversed by anyone, including the company that stored it. "Encrypt" and "hash" describe two different jobs, and using them interchangeably, as many news articles and even some software documentation carelessly do, is a factual error worth correcting every time you see it.

Encryption You Already Use Today

Once you know what to look for, encryption is everywhere in an ordinary day. When you see the padlock icon and "https://" (the "s" stands for secure) before any website address, including your school's portal or IRCTC, that connection is running the hybrid asymmetric-then-symmetric scheme described above, under a protocol called TLS. When you send a message on WhatsApp, it is protected end-to-end using the Signal Protocol, meaning the message is encrypted on your phone and only decrypted on the recipient's phone — not even WhatsApp's own servers, which merely relay the ciphertext, can read the content in between. When you enter your UPI PIN inside a payment app to complete a transaction, that PIN is encrypted on your device using public-key cryptography before it is transmitted onward through the UPI network operated by the National Payments Corporation of India (NPCI), so that the PIN is never exposed as plain text at any point in transit. In every one of these cases, the underlying contract is exactly the one you derived by hand with the five-letter word INDIA at the start of this chapter: plaintext, transformed by a key through a defined algorithm, into ciphertext that is meaningless to anyone without the matching key.

Summary

  • Encryption transforms readable plaintext into unreadable ciphertext using a secret key and a public, well-studied algorithm (Kerckhoffs's principle: security lives in the key, never in secrecy of the method).
  • The Caesar cipher shifts each letter by a fixed key, computed as (position + shift) mod 26; it is easy to break by brute force (only 25 keys) or frequency analysis (letter E is most common in English), which is exactly why real ciphers avoid one-to-one letter substitution.
  • Key space size, not cleverness, is what resists brute force: AES's 2128 keys (≈ 3.4 × 1038) make exhaustive search physically infeasible, unlike Caesar's 25.
  • Encoding (like Base64) uses no secret key and provides no confidentiality — it is not encryption.
  • Symmetric encryption uses one shared key for both encryption and decryption but cannot solve the problem of two strangers agreeing on a secret over an insecure channel.
  • Asymmetric (public-key) encryption uses a public key to lock data and a separate private key to unlock it, solving the key-distribution problem; RSA implements this using modular exponentiation, which is easy to compute forward but hard to reverse without the private key.
  • Real systems like HTTPS use a hybrid: asymmetric encryption once, to exchange a symmetric key safely, then fast symmetric encryption for the actual data.
  • Hashing is one-way and irreversible by anyone, unlike encryption, which is deliberately reversible by the key holder — passwords are hashed, not encrypted.

Check Your Understanding

  1. Encrypt the word "CBSE" using a Caesar shift of key = 5. Show the position number of each letter before and after the shift, including any wraparound.
  2. A Caesar-encrypted message has the ciphertext letter "K" appearing far more often than any other letter. Using frequency analysis, what is the most likely shift key, and what plaintext letter does K most likely represent? Explain your reasoning.
  3. A friend says, "I encrypted my file by converting it to Base64, so it's now secure." Explain precisely why this claim is false, using the definitions of encryption and encoding from this chapter.
  4. Using the toy RSA numbers n = 33, public key e = 3, private key d = 7, encrypt the message m = 5 by computing 53 mod 33 by hand, then decrypt your ciphertext back to 5 using successive squaring the way this chapter demonstrated for m = 4.
  5. Explain, in your own words, why HTTPS uses asymmetric encryption only briefly at the start of a connection and switches to symmetric encryption afterward, rather than using asymmetric encryption for the entire session.
  6. A classmate says, "My bank encrypts my password in its database, so even the bank's own employees can never see it." Identify the factual error in this statement and correct it using the encryption-versus-hashing distinction from this chapter.

Practice Exercises

Now it is time to practice! Complete these challenges to solidify your understanding:

  • Exercise 1: Write a short program that demonstrates the core concept from this chapter. Test it with at least 3 different inputs.
  • Exercise 2: Find a real-world example where encryption is used in an Indian company (like TCS, Infosys, Flipkart, or ISRO). Write a paragraph explaining the connection.
  • Exercise 3: Create a mind-map connecting encryption to at least 3 other topics you have studied.
← CompressionChatbots →

Found this useful? Share it!

📱 WhatsApp 🐦 Twitter 💼 LinkedIn