Module 13 · 17 min read · Free chapter
Cryptography and network security basics
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.
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 places. Numbering A as 0 to Z as 25, it is
Worked example 1. With , 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 , 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 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 users needs its own secret key, the number of keys is
Worked example 2. For 100 employees that is 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 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 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 and and compute and . Pick a public exponent with , then find the private exponent so that . The public key is and the private key is , and
Worked example 3 (RSA). Take and , so and . Choose , since . Then , because .
To encrypt the message , compute . To decrypt, compute , and a neat trick helps: , so
The receiver gets back . An attacker who knows only and must factor 33 to find and hence , which is trivial here but impossible in practice when 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 and a base . Asha picks a secret and sends , and Bina picks a secret and sends ; each then raises the received number to her own secret.
Worked example 4 (Diffie–Hellman). Let and , with Asha's secret and Bina's secret . Asha sends , and Bina sends . Asha computes and Bina computes , so both hold the key , which equals .
An eavesdropper sees 23, 5, 8 and 19 but must solve the discrete logarithm problem to recover or . 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 -bit hash is expected after about tries. So a 128-bit hash gives only about 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 with the private key: . Anyone can verify it with the public key: , so , which matches .
| 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:
- Explain the CIA triad and classify given attacks as passive or active, naming the goal each one breaks.
- Compare symmetric and asymmetric cryptography, including the number of keys and where each is used.
- Work a small RSA or Diffie–Hellman numerical and comment on why it is secure for large numbers.
- Design a defence for an office, choosing among firewall, IDS, VPN, certificates and user training.
Practice questions (our own, not previous-year questions).
- Explain the CIA triad with one example of an attack on each goal. Why is non-repudiation needed in banking? (10 marks)
- Using , and , find the RSA private key and encrypt the message . Explain why RSA is secure for large primes. (15 marks)
- 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 and , and check that , so is valid.
- Find from , which gives because .
- State the public key and the private key .
- Encrypt as , and note that returns 8.
- Explain that an attacker knows and but needs , which requires factoring , 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 , with only 25 useful keys.
- Symmetric keys for users number , while public-key needs only .
- 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 , and ; with , , we get .
- Diffie–Hellman with , , , gives the shared key 2.
- MD5 is 128 bits, SHA-1 160 bits and SHA-256 256 bits, and collisions appear after about 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.