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

Cybersecurity Fundamentals: Encryption, Authentication, and Staying Safe

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

The Message That Anyone Could Read

Say you are booking a train ticket on IRCTC and you type your UPI PIN to pay the fare. That PIN travels from your phone, across mobile towers, through your telecom operator's network, into IRCTC's servers, and back to your bank — dozens of computers your data passes through on the way, any one of which could, in theory, be watched by someone with the right access. If your PIN travelled as plain digits, "4 7 8 2", anyone tapping that connection at any point could simply read it off the wire. Yet UPI transactions happen safely, millions of times a day, in India. The reason is not that the internet became a private tunnel just for you — it is that mathematics makes the intercepted data useless to anyone except the intended receiver. That is the whole job of cybersecurity: not making information impossible to intercept, but making it useless once intercepted, and making sure that whoever claims to be on the other end really is who they say they are. Those are two separate problems — encryption (hiding the content) and authentication (verifying identity) — and this chapter builds both from first principles.

Building a Cipher From Scratch: The Caesar Shift

Start with the simplest possible idea for hiding a message: shift every letter forward in the alphabet by a fixed number of places. This is called a Caesar cipher, named after Julius Caesar, who reportedly used a shift of 3 to send military orders. "A" becomes "D", "B" becomes "E", and so on, wrapping back to the start once you pass "Z". The fixed number — 3 in this case — is called the key. Anyone who knows the key can reverse the shift and read the original message; anyone who does not know it just sees scrambled letters.

To implement this precisely, we need each letter's numeric position. In Python, ord('A') gives 65 and ord('a') gives 97 — these are the letters' positions in the ASCII table. If we subtract the base value (65 for uppercase, 97 for lowercase), we get a clean position from 0 to 25. Add the shift, and use the remainder after dividing by 26 (the modulo operator, %) so that shifting past "Z" wraps back to "A" instead of running off the alphabet:

def caesar_encrypt(text, shift):
    result = ""
    for char in text:
        if char.isalpha():
            base = ord('A') if char.isupper() else ord('a')
            result += chr((ord(char) - base + shift) % 26 + base)
        else:
            result += char
    return result

def caesar_decrypt(text, shift):
    return caesar_encrypt(text, -shift)

message = "ATTACK AT DAWN"
encrypted = caesar_encrypt(message, 3)
print(encrypted)

decrypted = caesar_decrypt(encrypted, 3)
print(decrypted)

Trace it letter by letter to see why this works. For "A": ord('A') - 65 = 0, then (0 + 3) % 26 = 3, then 3 + 65 = 68, which is chr(68) = 'D'. For "T": ord('T') - 65 = 19, (19 + 3) % 26 = 22, 22 + 65 = 87, which is "W". Working through the whole sentence, "ATTACK AT DAWN" becomes "DWWDFN DW GDZQ" — spaces are left untouched because char.isalpha() is false for them, so they fall into the else branch unchanged. The program prints:

DWWDFN DW GDZQ
ATTACK AT DAWN

Decryption uses the same function with a shift of -3. For "D": ord('D') - 65 = 3, then (3 + (-3)) % 26 = 0, then 0 + 65 = 65 = 'A'. Python's % operator always returns a non-negative result when the divisor is positive, even for a negative numerator — that is precisely what lets one function handle both encryption and decryption, just by flipping the sign of the shift.

Misconception: "A Secret Code Means the Message Is Secure"

A Caesar cipher looks unreadable at a glance, and it is tempting to conclude the message is now safe. It is not — and this is the first misconception worth correcting directly. There are only 25 possible shifts (26 minus the do-nothing shift of 0), so an attacker can simply try all 25 and read off the one that produces real words; this takes a computer a fraction of a second. Even against a cipher with far more possible keys, attackers do not need to guess blindly. English text has a predictable letter frequency — "E" is the most common letter, "T" and "A" follow — so in a long enough shifted message, whichever scrambled letter appears most often is very likely the shifted version of "E". This technique, called frequency analysis, breaks any cipher that always maps the same input letter to the same output letter, no matter how the key is chosen. The lesson: turning text into something unreadable to a human glance is not the same as making it computationally infeasible to break. Real encryption systems, like AES (Advanced Encryption Standard, used to protect your Wi-Fi traffic and app data) or the encryption behind UPI transactions, are built specifically to resist frequency analysis and every other known pattern-based attack — they operate on blocks of bits with mathematical transformations designed so that changing one input bit unpredictably changes many output bits, leaving no statistical fingerprint for an attacker to exploit.

The Real Obstacle: How Do Two People Agree on a Key?

Caesar's cipher, AES, and every cipher like them share one requirement: both the sender and the receiver must already possess the same secret key before they can communicate. This category is called symmetric encryption — one key, shared by both sides, used to both lock and unlock the message. That sounds fine until you ask: how did the two sides agree on the key in the first place, without an eavesdropper also learning it? If Alice has to send Bob the key over the same internet connection an attacker is watching, the attacker just intercepts the key along with everything else, and the whole scheme collapses. This is not a minor implementation detail — it is the central unsolved problem of symmetric encryption, and for centuries it had no good answer for two strangers who had never met in person. It is exactly the situation you are in every time your phone connects to a website it has never talked to before, like a new UPI merchant's payment page.

Asymmetric Encryption: Two Keys Instead of One

The solution, developed in the 1970s, is asymmetric encryption: instead of one shared key, each person generates a mathematically linked pair of keys — a public key, which they can hand out to absolutely anyone, including attackers, and a private key, which they never share with anyone. Data locked with a person's public key can only be unlocked with that same person's private key — not even the person who did the locking can reverse it. This breaks the deadlock completely, because the public key never needs to be kept secret in the first place.

The standard way to build intuition for this is the open-padlock analogy. Imagine Alice owns a padlock and its one matching physical key. She keeps the key locked in her own drawer and mails the open, unlocked padlock to Bob — anyone intercepting the post can see the padlock, but an open padlock reveals nothing useful. Bob puts his secret message in a box, clicks Alice's padlock shut on it, and mails the box back. Now the box is uncrackable by anyone except Alice, because only Alice's key — which never left her drawer — can open that specific padlock. Even Bob, who locked it, cannot open it again without Alice's key.

Asymmetric Encryption: Solving the Shared-Key Problem A Alice B Bob Step 1: Alice sends an OPEN padlock (her public key) to Bob. Attackers can see it too — that's fine, it can't lock anything by itself yet. Step 2: Bob locks his message using Alice's padlock, mails the box back. Now the box is locked — attackers who see it in transit cannot open it. Step 3: Only Alice's PRIVATE key — kept in her drawer, never sent — opens this padlock. Even Bob, who locked it, cannot open it again without that private key.

Real asymmetric algorithms like RSA do not use physical locks, of course — they rely on number-theory problems that are easy to compute in one direction and, with today's computing power, effectively impossible to reverse without the private key (for instance, multiplying two very large prime numbers is fast, but factoring the resulting huge number back into those two primes takes far longer than any adversary has patience for). The padlock picture captures the essential structural idea correctly: two mathematically linked keys, one that can be shared freely and one that must never leave its owner.

In practice, systems rarely use asymmetric encryption for the entire conversation, because the math involved is far slower than symmetric encryption. Instead, they use asymmetric encryption only for the hard part — securely agreeing on a fresh, one-time symmetric key — and then switch to fast symmetric encryption (like AES) for the rest of the actual conversation. This hybrid approach is exactly what happens every time your phone opens a banking app or an IRCTC page.

What the Padlock Icon in Your Browser Actually Promises

When you visit a website and see a small padlock next to the address bar, that connection is using HTTPS — HTTP running inside this encrypted channel, set up through a handshake that does roughly what the diagram above shows, plus one more step: the site proves its identity using a digital certificate, issued by an organisation called a Certificate Authority that has verified the site owns that domain. This is where a common and genuinely dangerous misconception needs correcting directly: many people assume the padlock icon means "this website is safe and legitimate." It does not. It only guarantees that the data travelling between your browser and that particular server is encrypted and that the server holds a valid certificate for its domain name — it says nothing about whether the domain itself is trustworthy. Free, automated certificate services exist today, which means a scam website at a look-alike domain like "irctc-refund-claim.com" can display exactly the same padlock as the real irctc.co.in. The padlock protects the pipe; it does not vouch for what is at the other end of it. Always check the actual domain name, not just the presence of the lock.

Authentication, Part 1: Proving Identity Without Storing the Secret

Encryption protects data in transit. A separate problem is authentication: when you log into an app, how does the app confirm you are really you, without simply keeping a plaintext list of everyone's passwords sitting on its server, ripe for theft if that server is ever breached? The tool for this is a hash function — a function that takes any input and produces a fixed-size output, called a hash or digest, with one crucial property: it is a one-way street. It is fast to compute the hash from the password, but computationally infeasible to work backwards from the hash to recover the original password. When you create an account, the app stores only the hash of your password, never the password itself. When you log in later, it hashes what you typed and checks whether the two hashes match.

To see why the design of the hash function matters so much, build a deliberately weak one and watch it fail. Here is a "toy" hash that simply adds up the character codes of every letter in the input:

def toy_hash(s):
    total = 0
    for ch in s:
        total += ord(ch)
    return total % 1000

print(toy_hash("dog"))
print(toy_hash("god"))

Trace it: "dog" has ord('d')=100, ord('o')=111, ord('g')=103, summing to 314, and 314 % 1000 = 314. "god" has the exact same three character codes, just added in a different order — addition does not care about order — so it also sums to 314. The program prints:

314
314

Two completely different words produced the identical hash. This is called a collision, and it is fatal for a security hash function: if an attacker can find any input that produces the same hash as your password, they can log in as you, whether or not they know your actual password. Real cryptographic hash functions, such as SHA-256 (used inside blockchain systems and password-storage libraries), are specifically engineered so that changing even a single character anywhere in the input scrambles the entire output unpredictably — this is called the avalanche effect — making it astronomically hard to find two different inputs that collide, and equally hard to reverse-engineer the input from the output. The toy hash above fails on both counts, which is exactly why nobody would ever use plain addition to protect a real password.

This is also the point to correct a second common misconception directly: students often use "encryption" and "hashing" as if they were interchangeable words for "scrambling data." They are not. Encryption is deliberately reversible — whoever holds the right key can decrypt it back to the original, because the sender needs the receiver to eventually read the message. Hashing is deliberately irreversible — the whole point of hashing a password is that not even the app's own server should ever be able to recover your original password from what it stored, only verify that a freshly typed attempt matches.

Salting: Why Identical Passwords Should Not Produce Identical Hashes

Suppose two different users on the same app both choose the password "india123". With a plain hash function, both accounts would store the exact same hash value. This is a problem because attackers maintain massive precomputed tables, called rainbow tables, that map common passwords straight to their hash values — if that hash appears in the table, both accounts are cracked in the same instant, and worse, the attacker instantly knows every other account on any other breached service sharing that same hash also uses "india123". The fix is a salt: a random string generated uniquely per user and combined with the password before hashing. Two users with the identical password "india123" end up with completely different stored hashes, because each was combined with a different random salt first, and a precomputed rainbow table becomes useless since it was not built for this specific salt.

Authentication, Part 2: Multi-Factor Authentication

A hashed, salted password is still only one piece of proof, drawn from a single category security professionals call "something you know." If that password ever leaks — through a data breach, a phishing page, or someone watching over your shoulder — a single-factor login is fully compromised. Multi-factor authentication (MFA) requires proof from at least two different categories: something you know (your password), something you have (your phone, which receives a one-time OTP), or something you are (a fingerprint or face scan, as used to unlock UPI apps or Aadhaar-linked services). This is why your bank sends an OTP by SMS before completing a UPI transaction above a certain amount: even if a scammer has somehow learned your UPI PIN, they still do not physically hold your phone to read the OTP. The two factors must be independent — if the OTP were also delivered to the same compromised channel as the password, the second factor would add no real protection.

Recognizing the Attacks That Bypass the Math Entirely

All the mathematics above — ciphers, key pairs, hashes, salts — can be flawless and still fail, because the weakest link in most real breaches is not the algorithm but the human using it. This category of attack is called social engineering: tricking a person into voluntarily handing over what encryption was built to protect. Phishing is its most common form — a fake message engineered to look like it came from a trusted source. A frequent pattern in India is an SMS or call claiming to be from your bank or IRCTC, warning that your KYC has expired or a refund is pending, with a link to a look-alike site or a request to "share the OTP to verify your identity." No legitimate bank ever needs your OTP read aloud to you over a phone call — the entire purpose of an OTP is that it stays between you and the service that generated it. The strongest cryptography in the world cannot stop an attack where the victim types their own password into the attacker's copy of the login page, or reads their own OTP aloud to someone pretending to be a bank employee. Recognizing these patterns — urgency, a request for information a legitimate party would never ask for, and a link that does not quite match the real domain name — is as much a part of cybersecurity as understanding the mathematics underneath it.

Check Your Understanding

  • Q1. Encrypt the word "HELP" using a Caesar shift of 5, then decrypt your result to check it. What are the intermediate letter positions for each letter?
    Answer: H(7)+5=12=M, E(4)+5=9=J, L(11)+5=16=Q, P(15)+5=20=U → "MJQU". Decrypting subtracts 5 from each: M(12)-5=7=H, and so on, returning "HELP".
  • Q2. Why can a Caesar cipher with any shift be broken almost instantly, even without trying all 25 shifts by hand?
    Answer: Frequency analysis — the most common letter in the scrambled text is very likely the shifted version of "E" (or another high-frequency letter), which immediately reveals the shift without brute-force guessing.
  • Q3. A website's login form stores toy_hash(password) using the addition-based function from this chapter. Explain one concrete way an attacker could log in without ever learning the real password.
    Answer: Because the toy hash only sums character codes, the attacker can submit any anagram of the real password (same letters, different order) and get an identical hash, which the server would incorrectly accept as a match.
  • Q4. A friend says, "This site has the padlock icon, so it must be the real IRCTC site." What is wrong with that reasoning?
    Answer: HTTPS certificates only prove the connection is encrypted and that the certificate was issued for the exact domain shown in the address bar — they say nothing about whether that domain is the genuine IRCTC or a look-alike scam domain that also obtained a free certificate.
  • Q5. Why does asymmetric encryption solve a problem that symmetric encryption alone cannot?
    Answer: Symmetric encryption needs both sides to already share the same secret key, which itself has to be transmitted somehow — creating a chicken-and-egg problem for two parties who have never met. Asymmetric encryption lets one side publish a public key openly (nothing secret needs to travel over the risky channel), while only the matching private key, which never leaves its owner, can decrypt what was locked with it.
  • Q6. Two users on the same app both pick the password "cricket2026". Why should their stored password hashes not be identical, and what mechanism prevents them from being identical?
    Answer: Identical hashes for a common password would make both accounts vulnerable to a precomputed rainbow-table lookup and would leak that both users share a password. Salting — combining each user's password with a unique random value before hashing — makes the two stored hashes different even though the underlying passwords match.

Summary

Cybersecurity for everyday digital life rests on two distinct pillars. Encryption hides content: symmetric encryption (one shared key, fast, but requires solving the key-distribution problem) and asymmetric encryption (a public/private key pair, which solves that exact problem by letting the public half travel in the open and reserving decryption power for the private half alone) work together in HTTPS to protect data such as a UPI PIN as it crosses the internet. Authentication verifies identity: one-way hash functions let a service confirm your password without ever storing it in reversible form, salting defeats precomputed attacks against common passwords, and multi-factor authentication adds an independent layer — something you have or something you are — so a single leaked password is not enough to break in. None of this mathematics protects you, however, against being persuaded to hand over your OTP or password directly to an attacker; recognizing phishing and social-engineering attempts remains a human skill that no algorithm can substitute for. A secret-looking scramble is not the same as cryptographic security, a padlock icon is not the same as a trustworthy website, and encryption is not the same as hashing — three distinctions this chapter deliberately built from working code and concrete traces, rather than from definitions alone, so that the difference is something you can verify, not just recite.

← Transfer Learning: Leveraging Pre-Trained ModelsThe Complete ML Pipeline: From Problem to Production—Predicting IPL Match Outcomes →

Found this useful? Share it!

📱 WhatsApp 🐦 Twitter 💼 LinkedIn