Computer Science and IT‹›⌂ 0:00 studied

Module 13 · 17 min read · Free chapter

Cryptography and network security basics

In short

Security protects confidentiality, integrity and availability. Symmetric ciphers such as AES use one shared key, while RSA uses a public and private key pair: with p = 3, q = 11 and e = 3, d = 7. A digital signature uses the sender's private key, and HTTPS is HTTP over TLS on port 443.

What are you preparing for? We show the practice and previous year questions of your exam.

Start from zero: a locked tiffin box

Imagine a delivery rider who carries your lunch from home to your office every day. Your mother puts a small lock on the tiffin so that nobody on the way can open it and see the food. She also ties a paper seal across the lid, so that if anyone tampers with it, you will notice at once.

Now think about what could still go wrong. A thief could steal the key and open the box, someone could swap the food and retie a fake seal, or the rider could simply never arrive.

Security is the art of stopping these three failures. Cryptography gives us digital locks and seals, and network security gives us guards at the gate, such as firewalls and intrusion detectors.

Why it matters. Every UPI payment, every railway ticket booked online and every government portal depends on these ideas. IT officer and RRB JE IT papers ask several questions on them in each sitting.

The CIA triad, threats and attacks

The three goals of security form the CIA triad. Confidentiality means only authorised people can read the data, like the lock on the tiffin. Integrity means the data cannot be changed without someone noticing, like the seal. Availability means the system works when it is needed, like the rider arriving on time.

Three more goals support the triad. Authentication proves who you are, for example by a password or an OTP, and authorisation then decides what you may do, such as a clerk who may view but not delete records. Non-repudiation means a sender cannot later deny having sent a message, which matters for bank transfers and signed orders.

Security people also separate three words. A vulnerability is a weakness, such as an unpatched server, a threat is a possible danger that could use that weakness, and an attack is the actual attempt.

Attacks are passive or active. A passive attack only listens: eavesdropping reads the messages and traffic analysis studies who talks to whom and how often. Passive attacks are hard to detect, so we prevent them with encryption. An active attack changes something: modification alters a message, masquerade pretends to be someone else, replay resends an old valid message, and denial of service blocks the service.

Why it matters. Many exam questions name an attack and ask which goal it breaks. Eavesdropping breaks confidentiality, modification breaks integrity and denial of service breaks availability.

Malware, phishing, DoS and man-in-the-middle

Malware is any software written to cause harm. Exams expect you to tell the types apart by how they spread and what they do.

Type How it spreads or works
Virus Attaches to a host file and spreads when that file runs
Worm Copies itself across the network with no user action
Trojan horse Looks like a useful program but hides harmful code
Ransomware Encrypts the victim's files and demands payment for the key
Spyware and keylogger Secretly records activity or every key pressed
Rootkit Hides deep in the operating system to stay unseen
Botnet Many infected machines controlled remotely by one attacker

Phishing is the most common attack on people rather than machines. A fake e-mail that looks like it came from your bank asks you to "verify your account" on a look-alike website, and the password you type goes to the attacker. The same trick by phone call is vishing and by SMS is smishing, and both are forms of social engineering, which tricks people instead of breaking code.

A denial-of-service (DoS) attack floods a server with so many requests that real users cannot get through. When the flood comes from thousands of machines at once, usually a botnet, it is a distributed DoS (DDoS), which is far harder to block because there is no single source.

In a man-in-the-middle (MITM) attack, the attacker secretly places himself between two parties, for example on a fake public Wi-Fi hotspot. Both sides think they are talking to each other, while the attacker reads or changes every message. Encryption with properly checked certificates is the main defence.

Why it matters. Most real losses in India come from phishing calls, fake links and ransomware, not from clever code-breaking. Knowing the attack names lets you both answer the exam and spot the next fraud message.

Classical ciphers and symmetric cryptography

Encryption turns readable plaintext into unreadable ciphertext using a key, and decryption turns it back. The oldest example is the Caesar cipher, which shifts every letter forward by kk places. Numbering A as 0 to Z as 25, it is

C=(P+k) mod 26,P=(C−k) mod 26C = (P + k) \bmod 26, \qquad P = (C - k) \bmod 26

Worked example 1. With k=3k = 3, A (0) becomes D (3), T (19) becomes W (22) and C (2) becomes F (5), so ATTACK becomes DWWDFN. The weakness is plain: there are only 25 useful keys, so an attacker simply tries them all, which is a brute-force attack.

A monoalphabetic substitution cipher replaces each letter by any other letter under a fixed table. Now the number of keys is 26!≈4×102626! \approx 4 \times 10^{26}, far too many to try. Yet it still falls to frequency analysis, because E, T and A are the most common letters in English text and their disguises stand out.

Modern symmetric ciphers use one shared secret key for both encryption and decryption. DES works on 64-bit blocks with a 56-bit effective key and 16 rounds, but 256≈7.2×10162^{56} \approx 7.2 \times 10^{16} keys can now be searched quickly, so it is retired; Triple DES applies it three times. AES is today's standard, with 128-bit blocks and keys of 128, 192 or 256 bits that use 10, 12 or 14 rounds.

The big problem of symmetric cryptography is key distribution. If every pair among nn users needs its own secret key, the number of keys is

n(n−1)2\frac{n(n-1)}{2}

Worked example 2. For 100 employees that is 100×992=4,950\dfrac{100 \times 99}{2} = 4{,}950 keys, each to be shared secretly. With asymmetric (public-key) cryptography each person has one public key and one private key, so 100 people need only 2×100=2002 \times 100 = 200 keys. Public-key methods are slow, so real systems use them to agree on a symmetric key and then switch to fast symmetric encryption, which is called hybrid encryption.

Why it matters. "How many keys for nn users?" and "what is the key size of DES?" are repeated almost every year. The trade-off, symmetric for speed and public-key for key exchange, explains how every secure website works.

Public-key cryptography: RSA and Diffie–Hellman with numbers

In public-key cryptography the public key is given to everyone and the private key never leaves its owner. Anything locked with one key of the pair can be opened only with the other.

RSA key generation. Choose two primes pp and qq and compute n=pqn = pq and ϕ(n)=(p−1)(q−1)\phi(n) = (p-1)(q-1). Pick a public exponent ee with gcd⁡(e,ϕ(n))=1\gcd(e, \phi(n)) = 1, then find the private exponent dd so that ed≡1(modϕ(n))ed \equiv 1 \pmod{\phi(n)}. The public key is (e,n)(e, n) and the private key is (d,n)(d, n), and

C=Me mod n,M=Cd mod nC = M^e \bmod n, \qquad M = C^d \bmod n

Worked example 3 (RSA). Take p=3p = 3 and q=11q = 11, so n=33n = 33 and ϕ(n)=2×10=20\phi(n) = 2 \times 10 = 20. Choose e=3e = 3, since gcd⁡(3,20)=1\gcd(3, 20) = 1. Then d=7d = 7, because 3×7=21=1×20+13 \times 7 = 21 = 1 \times 20 + 1.

To encrypt the message M=4M = 4, compute C=43 mod 33=64 mod 33=31C = 4^3 \bmod 33 = 64 \bmod 33 = 31. To decrypt, compute 317 mod 3331^7 \bmod 33, and a neat trick helps: 31≡−2(mod33)31 \equiv -2 \pmod{33}, so

317≡(−2)7=−128≡−128+132=4(mod33)31^7 \equiv (-2)^7 = -128 \equiv -128 + 132 = 4 \pmod{33}

The receiver gets back M=4M = 4. An attacker who knows only e=3e = 3 and n=33n = 33 must factor 33 to find ϕ(n)\phi(n) and hence dd, which is trivial here but impossible in practice when nn has more than 600 decimal digits.

Diffie–Hellman key exchange lets two people agree on a secret key over an open channel without ever sending it. They publicly agree on a prime pp and a base gg. Asha picks a secret aa and sends A=ga mod pA = g^a \bmod p, and Bina picks a secret bb and sends B=gb mod pB = g^b \bmod p; each then raises the received number to her own secret.

Worked example 4 (Diffie–Hellman). Let p=23p = 23 and g=5g = 5, with Asha's secret a=6a = 6 and Bina's secret b=15b = 15. Asha sends A=56 mod 23=15625 mod 23=8A = 5^6 \bmod 23 = 15625 \bmod 23 = 8, and Bina sends B=515 mod 23=19B = 5^{15} \bmod 23 = 19. Asha computes 196 mod 23=219^6 \bmod 23 = 2 and Bina computes 815 mod 23=28^{15} \bmod 23 = 2, so both hold the key K=2K = 2, which equals 590 mod 235^{90} \bmod 23.

An eavesdropper sees 23, 5, 8 and 19 but must solve the discrete logarithm problem to recover aa or bb. However, plain Diffie–Hellman does not prove who is on the other end, so an attacker in the middle can run one exchange with each side. That is why real systems sign the exchanged values with certificates.

Why it matters. RSA and Diffie–Hellman numericals with small primes are standard in IT officer and NIELIT papers. They are also the exact steps that run each time your browser shows a padlock.

Hash functions and digital signatures

A cryptographic hash function takes a message of any length and gives a short, fixed-length digest, like a fingerprint of the data. Change even one letter of the message and the digest changes completely. MD5 gives a 128-bit digest, SHA-1 a 160-bit digest and SHA-256 a 256-bit digest.

A good hash must have three properties. It must be one-way (preimage resistant), so the message cannot be found from the digest. It must be second-preimage resistant, so nobody can find a different message with the same digest as a given one. It must be collision resistant, so nobody can find any two messages with the same digest.

The birthday bound tells how strong collision resistance can be. A collision for an nn-bit hash is expected after about 2n22^{\frac{n}{2}} tries. So a 128-bit hash gives only about 2642^{64} collision strength, which is one reason MD5 and SHA-1 are now treated as broken and SHA-256 is used instead.

A digital signature joins hashing with public-key cryptography. The sender hashes the message and encrypts the digest with his own private key; the result is the signature. The receiver decrypts the signature with the sender's public key and compares it with a fresh hash of the received message, and if the two match, the message is genuine and unchanged.

Worked example 5. Using the RSA keys above, sign a digest h=2h = 2 with the private key: s=27 mod 33=128 mod 33=29s = 2^7 \bmod 33 = 128 \bmod 33 = 29. Anyone can verify it with the public key: 29≡−4(mod33)29 \equiv -4 \pmod{33}, so 293≡(−4)3=−64≡−64+66=229^3 \equiv (-4)^3 = -64 \equiv -64 + 66 = 2, which matches hh.

Goal Sender uses Receiver uses
Confidentiality (secret message) Receiver's public key Receiver's own private key
Digital signature Sender's own private key Sender's public key

Why it matters. "Which key is used to sign?" is among the most repeated security questions. A signature gives authentication, integrity and non-repudiation, but it does not hide the message; for that you also encrypt.

Certificates, PKI and HTTPS

Public-key cryptography has one hole. When a website sends you its public key, how do you know it is really the bank's key and not an attacker's? The answer is a digital certificate, a small file that says "this public key belongs to this name", signed by a trusted certificate authority (CA).

The common certificate format is X.509. A certificate holds the owner's name (such as the website's domain), the owner's public key, a validity period, the issuing CA's name and the CA's signature over all of it. The full system of CAs, registration authorities that check identities, the certificates themselves and the means to cancel them is called a public key infrastructure (PKI).

Trust works as a chain. Your browser and operating system come with a small list of root CA certificates already built in. A website's certificate is signed by an intermediate CA, whose certificate is signed by a root CA, and the browser checks each signature up the chain. A certificate that is stolen or wrongly issued is cancelled through a certificate revocation list (CRL) or an online status check (OCSP).

SSL, now replaced by TLS, uses all of this to protect a web connection. In the handshake, the browser says hello, the server sends its certificate, the browser checks it against its root CAs, and the two agree on a fresh symmetric session key using public-key methods such as Diffie–Hellman. After that, every byte is encrypted with the fast session key.

HTTPS is simply HTTP running over TLS, and it uses port 443 while plain HTTP uses port 80. The padlock in the address bar means the connection is encrypted and the certificate matched the domain name. It does not mean the website itself is honest, because a fraudster can also get a certificate for a look-alike domain.

Why it matters. Every online banking session, railway booking and exam form submission runs over TLS. Questions on "which port does HTTPS use?" and "what does a CA sign?" appear regularly.

Firewalls, IDS and VPN

Cryptography protects data on the move, but a network also needs guards at its gate. A firewall sits between a trusted network, such as an office LAN, and an untrusted one, such as the internet, and allows or blocks traffic by a set of rules.

There are three common kinds. A packet-filtering firewall checks each packet's source and destination address, port number and protocol, for example "allow port 443, block port 23". A stateful inspection firewall also remembers which connections are open, so it lets in replies to requests made from inside but blocks unasked traffic. An application-level gateway, or proxy firewall, works at the application layer and can inspect the actual content, such as blocking certain websites or file types.

An intrusion detection system (IDS) watches traffic or system activity and raises an alert when it sees an attack. A signature-based IDS matches known attack patterns, like an antivirus, so it misses new attacks. An anomaly-based IDS learns normal behaviour and flags anything unusual, so it can catch new attacks but gives more false alarms. An intrusion prevention system (IPS) sits in the traffic path and blocks the attack as well as reporting it.

A virtual private network (VPN) builds an encrypted tunnel across a public network, so that a remote employee or a branch office can use the head office network as if directly connected. Common VPN technologies are IPsec, which works at the network layer, and TLS-based VPNs.

Why it matters. Banks, railways and government departments must run firewalls, IDS and VPNs, and IT officers configure them. Questions often ask which device detects, which blocks and which encrypts.

Descriptive lens: how written papers ask this

Descriptive papers for IT officer posts, NIELIT and state Assistant Programmer exams ask about security in four ways:

  1. Explain the CIA triad and classify given attacks as passive or active, naming the goal each one breaks.
  2. Compare symmetric and asymmetric cryptography, including the number of keys and where each is used.
  3. Work a small RSA or Diffie–Hellman numerical and comment on why it is secure for large numbers.
  4. Design a defence for an office, choosing among firewall, IDS, VPN, certificates and user training.

Practice questions (our own, not previous-year questions).

  1. Explain the CIA triad with one example of an attack on each goal. Why is non-repudiation needed in banking? (10 marks)
  2. Using p=5p = 5, q=11q = 11 and e=3e = 3, find the RSA private key and encrypt the message M=8M = 8. Explain why RSA is secure for large primes. (15 marks)
  3. A bank branch wants its staff to work safely from home. Describe how a VPN, a firewall and an IDS together protect the bank's network. (10 marks)

Answer plan for question 2.

  • Compute n=5×11=55n = 5 \times 11 = 55 and ϕ(n)=4×10=40\phi(n) = 4 \times 10 = 40, and check that gcd⁡(3,40)=1\gcd(3, 40) = 1, so e=3e = 3 is valid.
  • Find dd from 3d≡1(mod40)3d \equiv 1 \pmod{40}, which gives d=27d = 27 because 3×27=81=2×40+13 \times 27 = 81 = 2 \times 40 + 1.
  • State the public key (3,55)(3, 55) and the private key (27,55)(27, 55).
  • Encrypt M=8M = 8 as C=83 mod 55=512 mod 55=17C = 8^3 \bmod 55 = 512 \bmod 55 = 17, and note that 1727 mod 5517^{27} \bmod 55 returns 8.
  • Explain that an attacker knows ee and nn but needs ϕ(n)\phi(n), which requires factoring nn, and that no fast method is known for numbers of hundreds of digits.

Quick revision

  • The CIA triad is confidentiality, integrity and availability, supported by authentication, authorisation and non-repudiation.
  • Passive attacks (eavesdropping, traffic analysis) read; active attacks (modification, masquerade, replay, DoS) change.
  • A virus needs a host file, a worm spreads by itself, and a trojan hides inside a useful-looking program.
  • The Caesar cipher is C=(P+k) mod 26C = (P + k) \bmod 26, with only 25 useful keys.
  • Symmetric keys for nn users number n(n−1)2\dfrac{n(n-1)}{2}, while public-key needs only 2n2n.
  • DES has a 64-bit block and a 56-bit key; AES has a 128-bit block and 128, 192 or 256-bit keys.
  • RSA uses n=pqn = pq, ϕ(n)=(p−1)(q−1)\phi(n) = (p-1)(q-1) and ed≡1(modϕ(n))ed \equiv 1 \pmod{\phi(n)}; with p=3p = 3, q=11q = 11, e=3e = 3 we get d=7d = 7.
  • Diffie–Hellman with p=23p = 23, g=5g = 5, a=6a = 6, b=15b = 15 gives the shared key 2.
  • MD5 is 128 bits, SHA-1 160 bits and SHA-256 256 bits, and collisions appear after about 2n22^{\frac{n}{2}} tries.
  • Sign with your private key; encrypt for secrecy with the receiver's public key.
  • A CA signs X.509 certificates, and HTTPS is HTTP over TLS on port 443.
  • A firewall filters, an IDS detects, an IPS blocks and a VPN encrypts a tunnel.

Check yourself

Exam-style questions on this chapter. Pick an answer to see the explanation. 0 of 15 answered

  1. A DDoS attack that keeps a railway booking site down mainly breaks:

  2. Which of these is a passive attack?

  3. Malware that spreads across a network by itself, without a host file or user action, is a:

  4. A fraud SMS with a fake bank link asking for your PIN is an example of:

  5. Using a Caesar cipher with k=3k = 3, the word ATTACK becomes:

  6. How many secret keys are needed so that every pair among 100 users can talk privately with symmetric cryptography?

  7. The effective key length of DES is:

  8. In RSA with p=3p = 3, q=11q = 11 and e=3e = 3, the private exponent dd is:

  9. With the RSA public key (e,n)=(3,33)(e, n) = (3, 33), the message M=4M = 4 encrypts to:

  10. In Diffie–Hellman with p=23p = 23, g=5g = 5, a=6a = 6 and b=15b = 15, the shared key is:

  11. For a 128-bit hash, a collision is expected after about how many tries?

  12. To put a digital signature on a message, the sender encrypts its hash with:

  13. A digital certificate mainly binds:

  14. HTTPS uses which default port?

  15. Which device detects an attack and raises an alert but does not block it?

Previous year questions

Previous year questions for UPSC CSE will appear here once each one is checked word for word against the official question paper.

Learn with AI

A tutor that asks instead of telling, a partner that argues the other side, and this chapter told through your own district.

Tell the tutor what you are stuck on. It will guide you with questions and give the answer after a few tries.

🙋 Raise a doubt or feedback

Stuck somewhere, or spotted a mistake? Write to the ExamHike team. We usually reply within a day, and you will see the reply on My progress.

Log in to ask a doubt or send feedback →

Frequently asked questions

What is the difference between a virus and a worm?

A virus needs a host file and user action to spread, while a worm copies itself across the network on its own.

How many keys do n users need in symmetric cryptography?

Every pair needs one key, so n(n − 1)/2 keys; 100 users need 4,950, while public-key needs only 2n.

Which key is used to make a digital signature?

The sender's private key signs the hash, and anyone verifies it with the sender's public key.

What is the difference between an IDS and an IPS?

An IDS detects attacks and raises alerts, while an IPS sits in the traffic path and also blocks them.

More in this module: IT fundamentals, security and law

Official sources

Facts in this chapter were checked against these official sources.

  1. GATE 2026 Computer Science and Information Technology (CS) syllabus, IIT Guwahati
  2. NPTEL Cryptography and Network Security (IIT Kharagpur, 106105162): classical ciphers, symmetric and public-key cryptography, hashing, signatures and network security