1. Gyanastra
  2. Computer Networks (UGC NET topics)
  3. Network Security
  4. Public Key Cryptography and RSA
Free lesson, no account needed 9 min read 10 practice questions after it

Computer Networks (UGC NET topics) · Network Security

Public Key Cryptography and RSA

Overview

Public key cryptography, also called asymmetric-key cryptography, uses two related keys per user: a public key that may be announced openly and a private key kept secret.
RSA is the standard public-key cryptosystem for confidentiality and digital signatures; its security depends on the difficulty of factoring a large composite integer.
In the UGC NET Computer Networks syllabus, this topic lies under Network Security and is usually tested through key selection, RSA key generation, modular arithmetic, encryption/decryption, digital signatures, and Diffie–Hellman key agreement.
Before studying it, you should know primes, modular arithmetic, Euler’s totient function, modular inverse, and basic plaintext–ciphertext terminology.

Key concepts

  • Plaintext is the original message MM; ciphertext is the transformed message CC; a key controls encryption and decryption.
    An encryption algorithm needs the message and the key; ciphertext is its output, and personal details of the user are not part of the algorithm.
  • Symmetric cryptography uses one shared secret key for both encryption and decryption, e.g. DES, AES, Caesar cipher. Asymmetric cryptography uses a key pair, e.g. RSA, ElGamal, ECC, DSA, and historically Knapsack.
  • In public-key cryptography, each user owns a public key and a private key. The public key is announced; the private key is never announced.
  • For confidentiality, the sender encrypts with the receiver’s public key; only the receiver can decrypt with the receiver’s private key.
  • For authentication and digital signature, the sender signs with the sender’s private key; anyone verifies with the sender’s public key. This gives integrity, authentication, and non-repudiation, but not confidentiality by itself.
  • Non-repudiation means the sender cannot later deny having sent the message. A digital signature provides this property.
  • A one-way function is easy to compute in one direction but computationally hard to invert.
    In public-key systems it helps make the private key impossible to derive from the public key; RSA uses a trapdoor one-way function based on modular exponentiation.
  • RSA security is based on the difficulty of integer factorization of n=pqn=pq, and more precisely on the RSA problem of extracting ee-th roots modulo nn.
    Diffie–Hellman uses the discrete logarithm problem; Knapsack uses a subset-sum type problem.
  • In RSA, public key is (e,n)(e,n) and private key is (d,n)(d,n). The primes p,qp,q and ϕ(n)\phi(n) are secret.
  • Diffie–Hellman is a key agreement protocol, not a message-encryption algorithm.
    Public values are a prime pp and a generator gg; each party chooses a private exponent and exchanges a public value, then both compute the same shared secret.
  • Basic Diffie–Hellman without authentication is vulnerable to a man-in-the-middle attack: an active attacker can establish separate shared keys with the two parties.

How it works

RSA key generation

  1. Choose two distinct large primes pp and qq.
  2. Compute the modulus n=pqn=pq. This nn is public.
  3. Compute Euler’s totient ϕ(n)=(p−1)(q−1)\phi(n)=(p-1)(q-1). Keep it secret in practice.
  4. Choose a public exponent ee such that 1<e<ϕ(n)1<e<\phi(n) and gcd⁡(e,ϕ(n))=1\gcd(e,\phi(n))=1.
  5. Compute the private exponent dd as the modular inverse of ee modulo ϕ(n)\phi(n): ed≡1(modϕ(n))ed\equiv1\pmod{\phi(n)}.
  6. Publish (e,n)(e,n); keep (d,p,q)(d,p,q) secret. In textbook RSA, the private key is often written as (d,n)(d,n).

Encryption and decryption

  1. Represent the message as an integer MM with 0≤M<n0\le M<n.
  2. Encryption: C≡Me(modn)C\equiv M^e\pmod n.
  3. Decryption: M≡Cd(modn)M\equiv C^d\pmod n.
  4. Correctness follows from ed=1+kϕ(n)ed=1+k\phi(n), so Cd=Med≡M(modn)C^d=M^{ed}\equiv M\pmod n under the standard RSA conditions.

Digital signature using RSA

  1. Sender computes a hash of the message.
  2. Sender encrypts/signs the hash with the sender’s private key.
  3. Receiver verifies with the sender’s public key.
  4. The receiver checks that the recovered hash matches the message hash.

Diffie–Hellman key agreement

  1. Public parameters: prime pp and generator gg.
  2. Ramesh chooses private aa, computes A=ga mod pA=g^a\bmod p.
  3. Geeta chooses private bb, computes B=gb mod pB=g^b\bmod p.
  4. They exchange AA and BB.
  5. Ramesh computes K=Ba mod pK=B^a\bmod p; Geeta computes K=Ab mod pK=A^b\bmod p. Both get K=gab mod pK=g^{ab}\bmod p.

For RSA with words, numbers are assigned to letters by a fixed convention. Many UGC papers use A=1,…,Z=26A=1,\ldots,Z=26, encrypt each number modulo nn, and then map the cipher number back to a letter, often reducing modulo 26; always check the convention stated or implied.

Figure. Notice that encryption uses the receiver’s public key (e,n) to compute C≡M^e mod n, while decryption uses the receiver’s private key (d,n). The ciphertext is sent over an insecure channel.

Formulas

  • n=pqn=pq: RSA modulus, product of two distinct primes.
  • ϕ(n)=(p−1)(q−1)\phi(n)=(p-1)(q-1): Euler’s totient for n=pqn=pq.
  • gcd⁡(e,ϕ(n))=1\gcd(e,\phi(n))=1: condition for a valid public exponent.
  • ed≡1(modϕ(n))ed\equiv1\pmod{\phi(n)}: private exponent condition; dd is the modular multiplicative inverse of ee modulo ϕ(n)\phi(n).
  • C≡Me(modn)C\equiv M^e\pmod n: RSA encryption.
  • M≡Cd(modn)M\equiv C^d\pmod n: RSA decryption.
  • ed=1+kϕ(n)ed=1+k\phi(n) for some integer kk: equivalent form of the inverse condition.
  • A=ga mod p,B=gb mod pA=g^a\bmod p,\quad B=g^b\bmod p: Diffie–Hellman public values.
  • K=Ba mod p=Ab mod p=gab mod pK=B^a\bmod p=A^b\bmod p=g^{ab}\bmod p: Diffie–Hellman shared secret.
  • For NN users, symmetric cryptography needs N(N−1)2\frac{N(N-1)}{2} pairwise keys; asymmetric cryptography needs NN key pairs, i.e. 2N2N individual keys.

Worked examples

Example 1: RSA key setup and encryption. Let p=5p=5, q=7q=7, e=5e=5. Find dd, then encrypt M=10M=10. n=5×7=35,ϕ(n)=4×6=24.n=5\times7=35,\qquad \phi(n)=4\times6=24. We need 5d≡1(mod24)5d\equiv1\pmod{24}. Since 5×5=25≡1(mod24)5\times5=25\equiv1\pmod{24}, d=5d=5. C=Me mod n=105 mod 35.C=M^e\bmod n=10^5\bmod35. Now 102=100≡30(mod35)10^2=100\equiv30\pmod{35}, 104≡302=900≡25(mod35)10^4\equiv30^2=900\equiv25\pmod{35}, so 105≡25×10=250≡5(mod35)10^5\equiv25\times10=250\equiv5\pmod{35}. Thus d=5d=5 and C=5C=5.

Example 2: Finding private exponent. Let p=7p=7, q=11q=11, e=13e=13. Find the smallest positive dd. n=77,ϕ(n)=6×10=60.n=77,\qquad \phi(n)=6\times10=60. Solve 13d≡1(mod60)13d\equiv1\pmod{60}. Since 13×37=481=8×60+113\times37=481=8\times60+1, d=37d=37. The public key is (13,77)(13,77) and the private key is (37,77)(37,77).

Example 3: RSA encryption with public key. Given public key (e,n)=(5,65)(e,n)=(5,65) and M=12M=12, find CC. C=125 mod 65.C=12^5\bmod65. First 122=144≡14(mod65)12^2=144\equiv14\pmod{65}. Then 124≡142=196≡1(mod65)12^4\equiv14^2=196\equiv1\pmod{65}. Hence 125≡1×12=12(mod65)12^5\equiv1\times12=12\pmod{65}. So C=12C=12.

Example 4: Two-step inverse problem. Let p=11p=11, q=19q=19, and d=13d=13. Find the public exponent ee. n=209,ϕ(n)=10×18=180.n=209,\qquad \phi(n)=10\times18=180. Need 13e≡1(mod180)13e\equiv1\pmod{180}, so 13e=1+180k13e=1+180k. Modulo 13, 1+180k≡1+11k≡0(mod13)1+180k\equiv1+11k\equiv0\pmod{13}. Since 11−1≡6(mod13)11^{-1}\equiv6\pmod{13}, k≡−6≡7(mod13)k\equiv-6\equiv7\pmod{13}. Taking k=7k=7: e=1+180×713=126113=97.e=\frac{1+180\times7}{13}=\frac{1261}{13}=97. Check: 13×97=1261=7×180+113\times97=1261=7\times180+1. Thus e=97e=97.

Example 5: Statement type. Statement I: ee must be relatively prime to ϕ(n)\phi(n). Statement II: dd is the inverse of ee modulo nn. Statement III: For confidentiality, the sender encrypts with the sender’s private key.
Statement I is true. Statement II is false because dd is inverse of ee modulo ϕ(n)\phi(n), not modulo nn. Statement III is false because confidentiality uses the receiver’s public key; the sender’s private key is used for signatures.

Comparison

FeatureSymmetric-key cryptographyAsymmetric-key cryptography
KeysOne shared secret keyPublic key and private key pair
Key distributionNeeds secure sharingPublic key can be announced, but authenticity must be guaranteed
SpeedFastMuch slower
ExamplesDES, AES, Caesar cipherRSA, ElGamal, ECC, DSA, Knapsack
Main useBulk data encryptionKey exchange, digital signatures, small data encryption
Keys for NN usersN(N−1)/2N(N-1)/2 pairwise keysNN key pairs
GoalSender usesReceiver or verifier usesProvides
ConfidentialityReceiver’s public keyReceiver’s private keyPrivacy
Digital signatureSender’s private keySender’s public keyIntegrity, authentication, non-repudiation
RSA itemMeaning
p,qp,qSecret distinct primes
n=pqn=pqPublic modulus
ϕ(n)=(p−1)(q−1)\phi(n)=(p-1)(q-1)Secret totient used in key generation
eePublic exponent, coprime to ϕ(n)\phi(n)
ddPrivate exponent, ed≡1(modϕ(n))ed\equiv1\pmod{\phi(n)}
(e,n)(e,n)Public key
(d,n)(d,n)Private key

Revision summary

  • Public key may be announced; private key must never be announced.
  • Confidentiality: encrypt with the receiver’s public key; decrypt with the receiver’s private key.
  • Signature: sign with the sender’s private key; verify with the sender’s public key.
  • RSA encryption and decryption are done modulo nn, not modulo ϕ(n)\phi(n).
  • The inverse condition is ed≡1(modϕ(n))ed\equiv1\pmod{\phi(n)}, not modulo nn.
  • e must satisfy gcd⁡(e,ϕ(n))=1\gcd(e,\phi(n))=1.
  • n=pqn=pq, ϕ(n)=(p−1)(q−1)\phi(n)=(p-1)(q-1) for distinct primes.
  • RSA security relies on factoring nn or solving the RSA problem; Diffie–Hellman relies on discrete logarithms.
  • Diffie–Hellman is key agreement, not encryption; unauthenticated DH suffers man-in-the-middle attack.
  • Raw textbook RSA is deterministic; practical systems use padding such as OAEP.
  • UGC key-size matches often use DES 56, AES 128/192/256, 3DES 168, and RSA 1024 in older match questions.

Previous-year exam insights

  • Direct concept questions ask which key is used for confidentiality, which key is kept private, what non-repudiation means, and why RSA can be used in reverse for digital signatures.
  • Numeric RSA questions give p,q,ep,q,e or dd and ask for nn, ϕ(n)\phi(n), the missing exponent, or ciphertext/plaintext.
    Check first whether the inverse is modulo ϕ(n)\phi(n) and the exponentiation is modulo nn.
  • Statement and matching questions test: ee is coprime to ϕ(n)\phi(n); dd is inverse of ee modulo ϕ(n)\phi(n); public key algorithm examples include RSA and Knapsack, while DES/AES are symmetric.
  • Diffie–Hellman questions check that p,gp,g are public, that the protocol agrees on a secret key, and that without authentication an active attacker can mount a man-in-the-middle attack.
  • Common traps: using modulo nn to compute dd, using modulo ϕ(n)\phi(n) for ciphertext, encrypting with the sender’s public key for confidentiality, or saying Diffie–Hellman encrypts messages.
  • Word-based RSA can appear; use the stated letter-number convention, keep each number less than nn, and convert back consistently.
  • Key-count questions distinguish symmetric N(N−1)2\frac{N(N-1)}{2} from asymmetric NN key pairs.
  • Questions about encryption algorithms themselves may test that a key and message are essential, ciphertext is output, and user details are not required.

Practice at PARIKSHA

You are ready for the PARIKSHA tests of this sub-topic when you can:

  1. Define asymmetric-key cryptography and state which key is public and which is private.
  2. Choose the correct key for confidentiality and for a digital signature.
  3. Generate RSA parameters from p,q,ep,q,e or p,q,dp,q,d and find the missing exponent using modular inverse.
  4. Encrypt and decrypt small RSA integers using modulo nn.
  5. Explain the roles of n,ϕ(n),e,dn,\phi(n),e,d and the condition ed≡1(modϕ(n))ed\equiv1\pmod{\phi(n)}.
  6. State the hard mathematical problem behind RSA, Diffie–Hellman, and Knapsack.
  7. Trace Diffie–Hellman key agreement and explain the man-in-the-middle weakness.
  8. Compare symmetric and asymmetric cryptography, including key counts and typical examples.
  9. Spot the traps between modulo nn and modulo ϕ(n)\phi(n), and between encryption for confidentiality and signing for non-repudiation.

Attempt the PARIKSHA sub-topic test first, then the subject test.

Pages 1–2 of 2