Number Theory and Cryptography

Learn the number theory behind public-key cryptography. Solve systems of congruences with the Chinese remainder theorem, compute huge powers modulo n by repeated squaring, and use Fermat's little theorem and Euler's theorem to simplify them and to test numbers for primality. Then build an RSA key pair, encrypt, decrypt and sign messages and prove why it works, and agree on a secret key with the Diffie–Hellman exchange. Every method is worked through with numbers small enough to check by hand.

IntermediateLesson 6 of 10 in Discrete Mathematics Course

What you will learn

  1. State the Chinese remainder theorem, build the solution of a system whose moduli are pairwise coprime, and solve systems step by step, including systems whose moduli share factors.
    • State the Chinese remainder theorem and build its solution
      Say exactly what the theorem guarantees, construct the solution from modular inverses, and see why the solution is unique modulo the product of the moduli.
    • Solve systems step by step, including shared factors
      Solve systems by back substitution, handle congruences with coefficients, decide when moduli that share a factor still allow a solution, and set up word problems.
  2. Evaluate very large powers modulo n quickly, use Fermat's little theorem to simplify powers and find inverses modulo a prime, and use it to test whether a number is prime.
    • Compute large powers with repeated squaring
      Use the binary expansion of the exponent to compute a power modulo n with few multiplications, and count how much work this saves.
    • Apply Fermat's little theorem
      State and prove Fermat's little theorem, use it to reduce exponents and find inverses modulo a prime, and avoid the usual misapplications.
    • Test numbers for primality with Fermat's theorem
      Use the Fermat test to prove that a number is composite, explain why passing the test does not prove primality, and recognize pseudoprimes and Carmichael numbers.
  3. Compute Euler's totient function, use Euler's theorem to simplify powers and find inverses for any modulus, and combine it with the Chinese remainder theorem and repeated squaring.
    • Compute Euler's totient function
      Count the residues coprime to n, compute the totient from a prime factorization, and see why the totient of an RSA modulus is as secret as its factors.
    • Prove and use Euler's theorem
      State and prove Euler's theorem, use it to reduce exponents and find inverses modulo any n, and know exactly when it applies.
    • Combine the theorems to evaluate powers
      Choose and chain the right tools, from splitting the modulus with the Chinese remainder theorem to reducing exponents and repeated squaring, to evaluate powers by hand and check the result.
  4. Explain what makes public-key cryptography possible, generate an RSA key pair, encrypt and decrypt messages, prove that decryption works, and sign and verify messages, including why textbook RSA is not used unprotected.
    • Explain the idea of public-key cryptography
      Contrast secret-key and public-key cryptography, explain one-way and trapdoor functions, and describe what the security of RSA rests on.
    • Generate an RSA key pair
      Choose the primes, compute the modulus and the totient, choose a valid public exponent and compute the private exponent with the extended Euclidean algorithm.
    • Encrypt, decrypt and prove that RSA works
      Encrypt and decrypt with RSA, prove with Euler's and Fermat's theorems that decryption recovers every message, speed up decryption with the Chinese remainder theorem, and explain the limits of textbook RSA.
    • Sign and verify messages with RSA
      Create and check RSA signatures, explain why practical signatures sign a hash, and show the forgeries that unprotected textbook signatures allow.
  5. Find orders and primitive roots, explain the discrete logarithm problem, and carry out and analyze the Diffie–Hellman key exchange.
    • Find orders, primitive roots and discrete logarithms
      Compute the order of a number modulo n, recognize and test primitive roots modulo a prime, and explain why discrete logarithms are hard to compute.
    • Run and analyze the Diffie–Hellman key exchange
      Carry out the Diffie–Hellman key exchange, explain what an eavesdropper sees and must solve, and recognize its limits and its relatives such as ElGamal encryption.

Number Theory and Cryptography study guide

5 chapters

1

Solve systems of congruences with the Chinese remainder theorem

Several remainder conditions can describe the same integer. The Chinese remainder theorem tells you when they fit together and how much information they give. You will construct a solution using inverses, prove its uniqueness, and solve systems by substitution. Shared factors need a compatibility check and change the least period of the solution class. These methods later let you split a large modular computation into smaller parts.

1.1 State the Chinese remainder theorem and build its solution

A list of remainders can identify one integer within a fixed range. The Chinese remainder theorem, or CRT, tells you when every list is possible and gives a formula for the integer.

What the theorem guarantees

Let the moduli m1,…,mk>1 be pairwise coprime: every pair has greatest common divisor 1. Put M=m1⋯mk. For any remainders a1,…,ak, the system x≡ai(modmi) has exactly one solution modulo M. Thus one solution lies in 0≤x<M, and every solution is obtained by adding an integer multiple of M.

Pairwise is stronger than having no factor common to the whole list. The moduli 6, 10 and 15 have overall gcd 1, but each pair shares a factor. For instance, a number congruent to 0 modulo 6 is even and cannot also be congruent to 1 modulo 10.

Build one term for each remainder

For each modulus, define Mi=M/mi and find yi≡Mi−1(modmi). The inverse exists because the other moduli are all coprime to mi. Then

x=∑i=1kaiMiyi

solves the system. To see why, reduce the sum modulo one chosen modulus mi. Every other term contains mi and vanishes. The remaining term is aiMiyi≡ai. Each term therefore supplies its own remainder without changing the others.

Work through a system

Solve x≡2(mod3), x≡3(mod5) and x≡2(mod7). Here M=105 and the partial products are 35, 21 and 15. Their inverses modulo 3, 5 and 7 are 2, 1 and 1, respectively: 35⋅2≡1(mod3), 21≡1(mod5) and 15≡1(mod7). The construction gives

x=2⋅35⋅2+3⋅21+2⋅15=233≡23(mod105).

Check every remainder: 23=7⋅3+2=4⋅5+3=3⋅7+2. The complete answer is x=23+105t for any integer t. It includes −82,23,128,233; the number 23 alone does not describe the full solution set.

Why there is only one class

If x and x′ both solve the system, every mi divides x−x′. Since the moduli are pairwise coprime, their product divides that difference. Hence x≡x′(modM). There are also exactly M lists of possible remainders and M residues modulo M, so the correspondence matches them one-to-one.

This correspondence preserves addition and multiplication. Modulo 105, 23 corresponds to (2,3,2) and 47 to (2,2,5). Add component by component and reduce to get (1,0,0), the remainders of 70. This lets a large calculation be split into smaller ones and reconstructed afterward.

With shared factors the product need not be the least period. The conditions x≡1 modulo 6, 10 and 15 together give x≡1(mod30). Writing only x≡1(mod900) would omit valid solutions such as 31 and 61.

Key Takeaways

  • Pairwise coprime moduli give one solution class modulo their product.
  • Each CRT construction term survives modulo its own modulus and vanishes modulo every other one.
  • Two solutions differ by a multiple of every modulus, hence by a multiple of their product.
  • Give the full answer as a congruence class, including its modulus.
  • Addition and multiplication can be carried out on the separate remainders.

1.2 Solve systems step by step, including shared factors

Back substitution builds the solution one congruence at a time. It also handles shared factors, provided you check that the conditions agree on those factors.

Turn a congruence into an equation

Solve x≡3(mod4), x≡5(mod9) and x≡2(mod5). The first condition means x=3+4t for an integer t. Substitute into the second:

3+4t≡5(mod9),4t≡2(mod9).

Since 4−1≡7(mod9), multiply by 7 to get t≡14≡5(mod9). Write t=5+9u and substitute back: x=23+36u. This describes every solution to the first two conditions, not just the representative 23.

Now impose the last condition: 23+36u≡2(mod5) gives 3+u≡2(mod5), so u≡4(mod5). Therefore x≡167(mod180). Check: 167 mod 4=3, 167 mod 9=5 and 167 mod 5=2.

Remove coefficients before combining

A condition such as 3x≡4(mod7) first becomes x≡6(mod7), since 3−1≡5 and 4⋅5≡6. If d=gcd⁡(a,m)>1, then ax≡b(modm) is solvable exactly when d∣b. When it is, divide the coefficient, right side and modulus by d before finding an inverse. Dividing only the coefficient and right side would preserve the wrong modulus.

Shared factors impose a compatibility check

For x≡a(modm) and x≡b(modn), a solution exists exactly when gcd⁡(m,n)∣a−b. Both remainders must describe the same residue modulo the common divisor. When they do, the full answer is one class modulo lcm⁡(m,n).

For x≡3(mod6) and x≡5(mod8), the gcd is 2 and the difference is 2, so the conditions agree. Set x=3+6t. Then 6t≡2(mod8) becomes 3t≡1(mod4), giving t≡3(mod4) and x≡21(mod24). In contrast, x≡1(mod4) and x≡2(mod6) require opposite parities and have no solution.

Split into prime powers when useful

A condition modulo 24 can be split into conditions modulo 8 and 3. Conditions on powers of the same prime agree exactly when their remainders agree modulo the smaller power. Thus x≡1(mod4) conflicts with x≡0(mod8). If two such conditions agree, keep the larger prime-power modulus; it already includes the smaller condition.

Translate a counting problem

“Fewer than 100 chairs leave 3 over in rows of 7 and 2 over in rows of 11.” Write x≡3(mod7) and x≡2(mod11). Testing 2,13,24,… gives 24. The class is 24+77t; among positive counts below 100 only 24 fits. The bound selects a particular member of the class after the congruences have been solved.

Why the gcd test is sufficient

Substitution gives mt≡b−a(modn). Put d=gcd⁡(m,n). If d∣b−a, divide to obtain (m/d)t≡(b−a)/d(modn/d). Now m/d and n/d are coprime, so an inverse exists and determines one class of parameters modulo n/d. Each increase of n/d in the parameter increases x=a+mt by mn/d=lcm⁡(m,n). This proves both existence and the claimed least period.

For compatible powers of the same prime, the larger condition already implies the smaller one. For example, x≡5(mod8) implies x≡1(mod4). Retaining the modulus-8 condition keeps exactly the integers that satisfy both; it does not discard an independent restriction.

Key Takeaways

  • Keep the integer parameter when substituting a solution into the next congruence.
  • Normalize coefficient congruences using the gcd and a modular inverse.
  • Shared-factor systems are solvable exactly when the remainders agree modulo the gcd.
  • A consistent two-modulus system repeats with least positive period equal to the lcm.
  • Compatible conditions on powers of one prime reduce to the larger-modulus condition.
  • Apply bounds from a counting problem after finding its solution class.
2

Compute modular powers and use Fermat's little theorem

Cryptographic calculations involve powers whose ordinary values are far too large to write down. Repeated squaring keeps their residues small and uses the binary exponent to limit the work. Fermat’s little theorem supplies an exponent period for prime moduli and explains a simple primality test. You will connect the algorithm to its proof and distinguish a conclusive compositeness witness from a number that merely passes a test.

2.1 Compute large powers with repeated squaring

A modular power can be computed without ever forming the huge ordinary power. Repeated squaring combines two facts: products can be reduced at every step, and every nonnegative integer exponent has a binary expansion.

Build powers whose exponents double

To compute be mod n, first reduce the base. Square it to obtain b2 modulo n, square again for b4, then continue with b8,b16,…. Each squaring doubles the exponent; it does not add 2 to it. Reduce after each multiplication so the factors stay below n and the unreduced product is at most (n−1)2.

For 5117 mod 391, write 117=64+32+16+4+1=11101012. The needed table is:

ExponentResidue modulo 391
15
225
4234
816
16256
32239
6435

For example, 252=625≡234, 2342=54756≡16 and 2562=65536≡239. Every row is obtained from the preceding row.

Select the 1-bits

Only the exponents 1, 4, 16, 32 and 64 occur in the binary sum. Multiply their residues in stages:

5⋅234≡388,388⋅256≡14, 14⋅239≡218,218⋅35≡201(mod391).

Thus 5117≡201(mod391). Multiplying all rows would use the exponent 1+2+4+8+16+32+64=127, not 117.

A right-to-left implementation starts with result 1 and power b mod n. Read each bit from the right: multiply the current power into the result for a 1-bit, then square the power before moving to the next bit. Skip the final unnecessary squaring. The first multiplication into 1 can be a copy. If the exponent is zero, the result stays 1, reduced modulo n.

Read the bits from the other direction

For a positive exponent, start with the base to account for the leading 1-bit. For every remaining bit, square the running result; for a 1-bit, also multiply by the base. Appending a binary digit changes an exponent u to 2u or 2u+1, which explains the two operations. With bits 1110101, the running residues are 5,125,316,151,224,128,201.

Count the work and keep the exponent straight

If a positive exponent has k bits and h 1-bits, these versions use k−1 squarings and h−1 extra multiplications. For 117, that is 6+4=10 operations instead of 116 successive multiplications by 5. A 2048-bit exponent needs at most 4094 operations of this kind.

Reducing the exponent modulo the modulus is not a valid general shortcut. Modulo 3, 25≡2, whereas replacing 5 by 5 mod 3=2 gives 22≡1. A valid exponent period comes from a theorem or a known cycle of powers. Small negative residues can shorten arithmetic: 25≡−1(mod11) immediately gives 215≡−1≡10(mod11).

Key Takeaways

  • Reduce the base and each intermediate product modulo the modulus.
  • Binary 1-bits select which squared powers to multiply.
  • Appending a binary bit means squaring, then multiplying by the base if the bit is 1.
  • For a positive exponent, the optimized cost is k−1 squarings plus h−1 further multiplications.
  • The modulus of a residue is not generally a valid period for its exponents.

2.2 Apply Fermat's little theorem

Fermat’s little theorem provides a period for powers modulo a prime. Its hypotheses determine which form you can use and which factors you may cancel in its proof.

State the two forms

If p is prime and p∤a, then ap−1≡1(modp). For every integer a, including multiples of p, the equivalent form is ap≡a(modp). When p∣a, the second form reads 0≡0; the first form would incorrectly claim 0≡1.

Why multiplication rearranges the residues

Take the nonzero residues 1,2,…,p−1 and multiply each by a. None becomes zero, since p divides neither factor. No two become equal: ia≡ja(modp) allows cancellation of a and gives i≡j(modp). Within the chosen range, that forces i=j. So the products are the same nonzero residues in another order.

For p=7 and a=3, the new list is 3,6,2,5,1,4. Multiply the whole list in either order to obtain

ap−1(p−1)!≡(p−1)!(modp).

Every factor of (p−1)! is nonzero modulo the prime, so the product has an inverse. Cancel that product to get the theorem. The cancellation is justified by coprimality; modular arithmetic does not permit cancellation of every nonzero integer for every modulus.

Shorten an exponent

Write e=q(p−1)+r. Then ae=(ap−1)qar≡ar(modp). For 2100 mod 13, use 100=8⋅12+4. Hence 2100≡24=16≡3(mod13). Reducing 100 modulo 13 instead would give exponent 9 and the wrong residue 5.

For 7222 mod 11, the relevant period is 10. Since 222≡2(mod10), the result is 72=49≡5(mod11). If the remainder exponent is zero, the answer is 1 because the original base is coprime to the prime.

Find an inverse

For p∤a, the identity a⋅ap−2≡1(modp) gives a−1≡ap−2(modp). Thus 3−1≡39≡4(mod11). Check by multiplication: 3⋅4=12≡1. The extended Euclidean algorithm gives the same answer and also works for composite moduli whenever the gcd is 1.

Check the modulus and the cycle

Primality is essential: using the first form with modulus 4 would claim 33≡1(mod4), but the actual remainder is 3. For a composite modulus, Euler’s theorem gives the corresponding result with a different exponent.

The theorem supplies a working period, not necessarily the shortest one. Modulo 11, 35≡1 even though p−1=10. The smallest positive exponent returning a coprime base to 1 is called its order. This smaller cycle later helps test bases for Diffie–Hellman.

Key Takeaways

  • For a prime p and p∤a, Fermat gives ap−1≡1(modp).
  • The form ap≡a(modp) also covers multiples of p.
  • Multiplication by an invertible residue permutes the nonzero residues modulo a prime.
  • Reduce exponents modulo p−1, and obtain inverses from exponent p−2.
  • A working exponent period can exceed the order of the base.

2.3 Test numbers for primality with Fermat's theorem

Fermat’s theorem gives a one-sided test for primality. A failed equality settles the question; a successful equality leaves open the possibility that a composite number happens to pass.

Test a candidate

For an odd integer n>3, choose 1<a<n−1 and compute an−1 mod n by repeated squaring. If the result differs from 1, n is composite and a is a Fermat witness. Every prime would satisfy the equality for such a base, so failure rules out primality.

For n=91, the computation gives 290≡64(mod91). Since 64 differs from 1, 91 is composite. This proves compositeness without requiring the factors 7⋅13 to be found. A witness generally supplies a contradiction to primality, not a factorization.

If a gcd calculation first gives 1<gcd⁡(a,n)<n, it already supplies a factor and proves compositeness. Exponentiation is then unnecessary.

A pass can be misleading

A number that passes is a probable prime to that base. A composite number that passes is a Fermat pseudoprime to that base. The base is part of the description: passing for one base need not mean passing for another.

For example, 341=11⋅31 is composite, yet 2340≡1(mod341). It is the smallest base-2 pseudoprime. Base 3 exposes it because 3340≡56(mod341). One failed test outweighs any number of successful tests: a prime cannot fail even one valid test.

Carmichael numbers fool every coprime base

A Carmichael number is a composite integer satisfying an−1≡1(modn) for every base coprime to it. The smallest is 561=3⋅11⋅17; 1105 and 1729 are further examples. Alford, Granville and Pomerance proved in 1994 that infinitely many exist.

Korselt’s criterion characterizes them: a composite integer is Carmichael exactly when it is squarefree and p−1∣n−1 for every prime divisor p. For 561, the prime factors are distinct and 560 is divisible by 2, 10 and 16. Both parts matter; the divisibility conditions alone cannot replace squarefreeness.

Bases sharing a factor still expose 561. For instance, 3560≡375(mod561), and gcd⁡(3,561)=3 already explains its compositeness. But repeatedly selecting coprime bases will never expose a Carmichael number. When its prime factors are large, a random base is unlikely to hit one of them.

Why stronger tests are useful

RSA key generation needs large primes, so software tests candidates with stronger methods such as Miller–Rabin. The prime number theorem estimates the fraction of primes near N as 1/ln⁡N. Near 21024 this is about one in 710 integers, or one in 355 odd integers. Selecting odd candidates saves work, but their primality still needs testing. The Fermat test explains the distinction between evidence that a number may be prime and a certificate that it is composite.

Key Takeaways

  • A Fermat witness proves compositeness without necessarily finding a factor.
  • A successful Fermat test gives a probable prime to one base.
  • A pseudoprime is composite despite passing the test for its specified base.
  • Carmichael numbers pass for every coprime base.
  • Korselt’s criterion requires both squarefreeness and divisibility by every prime-factor period.
  • Stronger primality tests avoid the Fermat test’s Carmichael weakness.
3

Work with Euler's totient function and Euler's theorem

Euler’s totient counts which residues can be inverted. Its prime-factor formula leads to an exponent theorem that works for composite moduli as well as primes. You will prove that theorem by rearranging coprime residues, then combine it with repeated squaring and CRT. The important choice is local: a base may be invertible modulo one factor and divisible by another, so each part of a calculation may need a different argument.

3.1 Compute Euler's totient function

Euler’s totient function counts the residues that have modular inverses. Its value is easy to compute from a prime factorization, and for an RSA modulus that connection also explains why the totient must stay secret.

Count the coprime integers

For a positive integer n, φ(n) counts the integers k with 1≤k≤n and gcd⁡(k,n)=1. For 12, those integers are 1,5,7,11, so φ(12)=4. They form a reduced residue system modulo 12. The endpoint 12 is not counted because it shares a factor with itself. The special value φ(1)=1 follows because gcd⁡(1,1)=1.

For every n≥3 the totient is even. Each coprime residue k pairs with n−k, also coprime to n. No such residue pairs with itself: if 2k=n and n≥3, then k is not coprime to n.

Start with primes and prime powers

If p is prime, every integer from 1 to p−1 is coprime to it, so φ(p)=p−1. For pk, the excluded integers are exactly the multiples of p. There are pk−1 of these among the first pk integers, giving

φ(pk)=pk−pk−1=pk−1(p−1).

Thus φ(8)=4, φ(9)=6 and φ(27)=18. The tempting formula (p−1)k is wrong: it would give 4 for φ(9) instead of 6.

Combine distinct prime factors

When gcd⁡(m,n)=1, the CRT matches each residue modulo mn to a unique pair of residues modulo m and n. A residue is coprime to mn exactly when both components are coprime to their respective moduli. Therefore φ(mn)=φ(m)φ(n).

Combining the prime-power formulas gives

φ(n)=n∏p∣n(1−1p),

where the product takes each distinct prime divisor once. For 360=23⋅32⋅5, this gives 360⋅12⋅23⋅45=96. Similarly, φ(100)=40 and φ(1001)=6⋅10⋅12=720. Multiplicativity requires coprime factors: φ(2)φ(2)=1, but φ(4)=2.

Recover RSA factors from the totient

For distinct primes p,q and n=pq, φ(n)=(p−1)(q−1)=n−p−q+1. Hence p+q=n−φ(n)+1. Knowing the sum and product determines the factors as the roots of

t2−(n−φ(n)+1)t+n=0.

With n=3233 and φ(n)=3120, the sum is 114. The discriminant is 1142−4⋅3233=64, so t=(114±8)/2 gives 61 and 53. Conversely, those factors immediately give the totient. For a modulus known to be a product of two distinct primes, recovering its exact totient and factoring it can therefore be reduced to each other.

Key Takeaways

  • The totient counts residues coprime to the modulus.
  • For prime powers, subtract the multiples of the prime.
  • Totients multiply over coprime factors; apply one product-formula factor per distinct prime.
  • For distinct primes, φ(pq)=(p−1)(q−1).
  • The exact totient of a two-prime RSA modulus reveals its prime factors.

3.2 Prove and use Euler's theorem

Euler’s theorem extends Fermat’s little theorem to composite moduli. The key requirement is that the base have an inverse modulo the modulus.

State the theorem

If gcd⁡(a,n)=1, then aφ(n)≡1(modn). For prime n=p, the value φ(p)=p−1 recovers Fermat’s theorem. For composite moduli the totient counts the invertible residues that replace the prime case’s full list of nonzero residues.

Prove it by rearranging a reduced residue system

Let r1,…,rφ(n) represent all residues coprime to n. The products ari remain coprime to n. They are also distinct modulo n: an equality ari≡arj allows cancellation of a because its inverse exists. Thus multiplication by a rearranges the reduced residue system.

Put R=r1⋯rφ(n). Multiplying all the original and rearranged residues gives aφ(n)R≡R(modn). Every factor of R is coprime to n, so R can be cancelled. This gives aφ(n)≡1(modn). Using all nonzero residues for a composite modulus would break this proof because their product may lack an inverse.

Reduce powers and find inverses

Write e=qφ(n)+r. Euler gives ae≡ar(modn). The last digit of 7222 is found modulo 10: φ(10)=4 and 222≡2(mod4), so 7222≡49≡9(mod10). For the last two digits of 31000, use φ(100)=40. The exponent reduces to zero, giving residue 1; two-digit formatting makes the answer “01.”

An inverse follows from a⋅aφ(n)−1≡1. Modulo 20, φ(20)=8, so 7−1≡77. Since 72≡9 and 74≡1, 77≡1⋅9⋅7=63≡3(mod20). Check 7⋅3≡1. Euclid can find the same inverse without knowing the totient.

Respect the base condition

For a=2,n=10, the gcd is 2 and 2φ(10)=16≡6, not 1. A zero remainder exponent would therefore give a false answer. Repeated squaring still works for this base; splitting the modulus may also help.

The totient need not be the smallest valid period. Every odd number squares to 1 modulo 8, even though φ(8)=4. The order is the smallest positive exponent returning a chosen coprime base to 1, and divides the totient.

Work from the top of a power tower

For the last digit of 777, the outer exponent is 77. It needs reduction modulo 4, not modulo 10. Since 7≡−1(mod4), 77≡3(mod4). Thus 777≡73=343≡3(mod10). The modulus used to shorten an exponent can itself be part of a second modular calculation.

Key Takeaways

  • Euler’s theorem requires gcd⁡(a,n)=1.
  • Multiplication by a coprime base permutes a reduced residue system.
  • Use φ(n) as an exponent period and aφ(n)−1 as an inverse.
  • A valid period may be larger than the base’s order.
  • In a power tower, reduce the upper exponent using the period of the outer base.

3.3 Combine the theorems to evaluate powers

Large modular powers often become short calculations when you choose a different method for each factor of the modulus. The CRT joins the results after Fermat, Euler or direct powers have handled the smaller pieces.

Choose the route for each factor

Start by checking the gcd of the base and the modulus. If a factorization is available, split the modulus into pairwise coprime factors, usually its prime powers. Check coprimality separately for each piece. Use Fermat for a prime piece and Euler for a composite piece when the base is invertible there. Otherwise, compute the power directly or look for divisibility that makes its remainder zero. Finish with repeated squaring and reconstruct the residue by CRT.

The exponent period belongs to the particular modulus and base. A reduction valid for one piece need not be valid for another. Recombination also requires the moduli, not just the list of remainders.

Recompute a power in two smaller systems

For 5117 mod 391, use 391=17⋅23. Modulo 17, Fermat shortens the exponent to 117 mod 16=5, giving 55≡14(mod17). Modulo 23, the exponent becomes 117 mod 22=7, giving 57≡17(mod23).

Now solve x≡14(mod17) and x≡17(mod23). Write x=14+17t, so 17t≡3(mod23). Since 17−1≡19, t≡57≡11(mod23). Hence x=14+187=201 and the result is 201(mod391). Its remainders are indeed 14 and 17, matching the independent repeated-squaring calculation.

Split three prime factors

For 21000 mod 1001, factor 1001=7⋅11⋅13. Fermat gives exponents 4 modulo 6, 0 modulo 10 and 4 modulo 12. The power therefore has remainders 2 modulo 7, 1 modulo 11 and 3 modulo 13.

Combine the first two conditions by setting x=1+11t. Then 1+4t≡2(mod7), so t≡2(mod7) and x=23+77u. The final condition gives 10+12u≡3(mod13), hence u≡7(mod13). This produces x=562. Check 562 mod 7=2, 562 mod 11=1 and 562 mod 13=3.

Working directly modulo 1001, Euler would shorten 1000 only to 1000 mod 720=280. Splitting makes the arithmetic use bases below 13 and exponent remainders below 12.

Let a shared factor guide the calculation

For 6100 mod 15, Euler cannot be used with the whole modulus because gcd⁡(6,15)=3. Modulo 3 the power is zero; modulo 5 the base is 1, so the power is 1. The system x≡0(mod3), x≡1(mod5) gives x≡6(mod15).

Adding the component remainders would give 1 and fail modulo 3. CRT reconstruction is a solving step, not an addition rule. In RSA, the same split into prime factors both speeds decryption and supplies a correctness proof for messages that share a factor with the modulus.

Show the local arithmetic

In the calculation modulo 17, 52=25≡8 and 54≡82≡13, so 55≡13⋅5≡14. Modulo 23, 52≡2 and 54≡4; hence 57≡4⋅2⋅5=40≡17. The exponent reductions leave short powers, and the squaring method evaluates those powers without large integers.

A prime-power component needs its own divisibility check. A base divisible by 2 is zero modulo 2, but its square need not be zero modulo 8: 62≡4(mod8). One more factor gives 63≡0(mod8). If Euler is unavailable in such a component, direct squaring tracks when divisibility becomes sufficient; declaring every positive power zero would be incorrect.

Key Takeaways

  • Check coprimality separately in every factor modulus.
  • Shorten an exponent with the theorem valid for that part, then use repeated squaring.
  • Solve a CRT system to recombine the remainders.
  • A shared factor can make one component zero while another uses a power theorem.
4

Explain and carry out RSA encryption and signatures

RSA turns modular exponentiation into a public operation with a private inverse. You will follow a complete key pair from its prime factors to encryption, decryption and signatures, and prove why the inverse works for every message residue. The same arithmetic also exposes weaknesses in the bare formulas. Understanding those weaknesses explains why practical encryption and signing add carefully designed encoding and padding.

4.1 Explain the idea of public-key cryptography

Public-key cryptography separates an operation anyone may perform from one that requires secret information. Number theory supplies functions that are fast in the public direction and believed hard to reverse without a trapdoor.

Two ways to distribute keys

In symmetric cryptography, the same secret key encrypts and decrypts. A simple shift cipher illustrates the roles: with letters numbered 0 through 25, c=(m+k) mod 26 and m=(c−k) mod 26. Both parties need the shift k. Agreeing on a secret with someone over a channel others can read is the key distribution problem.

In public-key cryptography, each person publishes a public key and keeps a private key secret. A sender encrypts with the recipient’s public key; the recipient decrypts with the corresponding private key. A signature has different roles: its maker signs with a private key and others verify with that maker’s public key. Publishing one member of the pair must leave the private operation infeasible for an outsider.

Easy forward, hard backward

A one-way function is easy to compute but computationally hard to invert. A trapdoor function has secret information that makes inversion efficient. In RSA, the public calculation is M↦Me mod n. Repeated squaring makes it efficient. The private exponent d makes the inverse operation efficient.

Multiplying two large primes is fast; recovering them from their product is much harder with known classical algorithms. For RSA, factoring n=pq gives φ(n) and then d. Conversely, a valid private exponent lets the modulus be factored efficiently. Computing the private key and factoring are therefore closely linked. Whether solving an arbitrary RSA ciphertext without recovering the key is equally hard remains an open mathematical question.

Size and computational assumptions

NIST SP 800-57 Part 1 Revision 5 estimates about 112 bits of security for a 2048-bit RSA modulus and about 128 bits for 3072 bits. A 2048-bit integer has 617 decimal digits. A larger modulus does not give the same number of security bits: attacks exploit number-theoretic structure, not just a search over all integers. The small keys used for hand calculations can be factored immediately.

The best known general classical factoring method is the number field sieve, with super-polynomial running time. Hardness has not been proved. Shor’s algorithm would factor integers and find discrete logarithms efficiently on a sufficiently large, error-corrected quantum computer. NIST published its first post-quantum standards, FIPS 203, 204 and 205, in August 2024, using different mathematical foundations.

From a message to an integer

RSA operates on 0≤M<n. A hand encoding may use A=00 through Z=25, so “HI” becomes 0708, the integer 708. Such a block must fit below the modulus. In practical encryption, public-key methods usually protect a short random symmetric key, which then protects the longer data.

Diffie and Hellman published public-key ideas and their exchange in 1976. Rivest, Shamir and Adleman described RSA at MIT in 1977. Cocks had found an equivalent system at GCHQ in 1973; that work became public in 1997.

Key Takeaways

  • Symmetric encryption requires a shared secret; public-key encryption separates public and private keys.
  • Encrypt with the recipient’s public key and verify with the signer’s public key.
  • RSA is easy to compute using repeated squaring and easy to invert with its trapdoor.
  • Factoring an RSA modulus reveals the private key; a valid private exponent also permits factoring.
  • RSA’s security rests on computational assumptions, with different classical and quantum attack models.
  • An RSA message representative is an integer below its modulus.

4.2 Generate an RSA key pair

An RSA key pair is built so that encryption followed by decryption raises a message to an exponent that acts like 1. The crucial inverse is taken modulo a period of powers, not modulo the message modulus.

Build the modulus and choose the public exponent

Choose distinct primes p,q. Compute n=pq and φ(n)=(p−1)(q−1). Select e with 1<e<φ(n) and gcd⁡(e,φ(n))=1. Then find d satisfying ed≡1(modφ(n)).

For p=61,q=53, the modulus is n=3233 and the totient is 60⋅52=3120. Choose e=17. Its gcd with 3120 is 1, so it has an inverse. Choosing e=3 would fail because 3 divides 3120. The exponent need not be prime; the requirement is coprimality with the totient.

Compute the private exponent

Apply Euclid to 3120 and 17:

3120=183⋅17+9, 17=9+8,9=8+1.

Work backward:

1=9−8=2⋅9−17 =2(3120−183⋅17)−17=2⋅3120−367⋅17.

Thus the inverse of 17 is −367(mod3120). Choose the positive representative d=2753. Check 17⋅2753=46801=15⋅3120+1. This last equality is the property needed by the correctness proof.

Computing 17−1(mod3233) would answer a different inverse problem. The modulus 3233 controls message residues; the totient 3120 controls the exponent relation used here.

Decide what is public

Publish (n,e)=(3233,17). Keep d=2753 secret, along with p,q and φ(n). Any one of the prime factors reveals the other by division. The exact totient reveals their sum and thus both factors. Keeping only d secret while publishing the factorization would therefore leave the key exposed.

Distinct primes matter. If p=q, the modulus is a square whose prime factor is recovered by taking its integer square root. Its totient is p(p−1), so the two-distinct-prime formula would also be wrong.

Alternative exponent periods

RSA can instead use λ(n)=lcm⁡(p−1,q−1). Here λ(3233)=lcm⁡(60,52)=780. The inverse of 17 modulo 780 is 413 because 17⋅413=7021=9⋅780+1. Both 413 and 2753 work; they are congruent modulo 780. Their exponent products are 1 modulo both prime-factor periods, which is enough for correctness.

A common public exponent is 65537=216+1. Its binary representation has only two 1-bits, allowing 16 squarings and one extra multiplication. Coprimality must still be checked for the selected primes. In that formulation, a valid public exponent can exceed the totient; the small-range convention above selects a convenient representative for hand calculations. Large keys use randomly selected primes found by strong primality tests, with each prime about half the modulus’s bit length.

Key Takeaways

  • Choose two distinct primes and compute their product and totient.
  • The public exponent must be coprime to the exponent modulus.
  • Use extended Euclid to compute d=e−1(modφ(n)).
  • Publish n,e and protect the private exponent, factors and totient.
  • An inverse modulo λ(n) also gives a working RSA private exponent.

4.3 Encrypt, decrypt and prove that RSA works

RSA encryption and decryption are modular powers. The correctness proof has two parts: Euler handles messages coprime to the modulus, and Fermat plus CRT covers every remaining message.

Encrypt and decrypt

For the recipient’s public key (n,e), encode the message as 0≤M<n and compute C=Me mod n. The recipient computes Cd mod n. With n=3233,e=17,d=2753 and M=65, the ciphertext is 6517 mod 3233=2790; decrypting gives 27902753 mod 3233=65. Both computations use repeated squaring. The 12-bit exponent 2753 needs 11 squarings and 4 further multiplications in the optimized method.

The range matters because decryption returns a residue. Encrypting the integer 3300 with this modulus and decrypting returns 3300 mod 3233=67. It cannot distinguish two integers in the same congruence class.

First prove the coprime case

Write ed=1+kφ(n). If gcd⁡(M,n)=1, Euler gives

Cd≡Med=M(Mφ(n))k≡M(modn).

The coprimality condition belongs to Euler’s theorem. It cannot be dropped just because a message is within range.

Cover messages sharing a factor

Work separately modulo p and q. If p∣M, then both Med and M are zero modulo p. If p∤M, use Fermat and p−1∣ed−1 to obtain Med≡M(modp). Repeat for q. The two residues match those of M, so the CRT gives equality modulo pq=n.

This proof covers M=122=2⋅61 for the running key, even though the gcd with 3233 is 61. Zero is also recovered by the same divisibility case. For a private exponent chosen modulo λ(n), the proof works because both p−1 and q−1 divide ed−1.

Use CRT to shorten private computations

For the ciphertext 2790, compute dp=2753 mod 60=53 and dq=2753 mod 52=49. The component messages are 4553 mod 61=4 and 3449 mod 53=12. Recombine x≡4(mod61) and x≡12(mod53). Writing x=4+61t gives 8t≡8(mod53), so t≡1 and x=65. At large sizes, doing both powers with roughly half-sized numbers and exponents commonly gives about a fourfold speedup.

Understand what the bare formula reveals

Textbook RSA is deterministic: encrypting the same message twice gives the same ciphertext. Anyone can encrypt guesses with the public key and compare them. Also, 0 and 1 encrypt to themselves. If Me<n, reduction never occurs: for e=3, a message 10 gives ciphertext 1000, exposing 10 by an ordinary cube root. Practical RSA encryption applies randomized padding, such as OAEP, before the public operation.

Follow the encryption power

For exponent 17=16+1, repeated squaring of 65 modulo 3233 gives 652≡992, 654≡1232, 658≡1547 and 6516≡789. Multiply the selected entries: 789⋅65=51285=15⋅3233+2790. This produces the ciphertext 2790 using four squarings and one further multiplication.

The private exponent has a less sparse binary expansion: 2753=2048+512+128+64+1. Its largest selected power needs eleven squarings to reach exponent 2048; combining the five selected residues needs four more multiplications. The public and private operations follow the same algorithm, but the bit patterns explain their different costs. Re-encrypting a recovered representative with the public exponent checks the private computation without repeating its longer exponentiation.

Key Takeaways

  • Encrypt with C=Me mod n and decrypt with Cd mod n.
  • The input representative must satisfy 0≤M<n.
  • Euler proves correctness for coprime messages; Fermat and CRT prove it for every message.
  • CRT decryption computes separate powers modulo the private primes and recombines them.
  • Determinism and small unpadded messages expose weaknesses in textbook RSA.
  • Randomized padding is part of practical RSA encryption.

4.4 Sign and verify messages with RSA

A digital signature supports checks on message origin and integrity. It answers a different question from encryption: who authorized this message, and has it changed?

Sign with the private key, verify with the public key

In textbook RSA, a signature on a representative 0≤M<n is S=Md mod n. A verifier computes Se mod n and checks whether the result equals M. The correctness argument is the same identity Med≡M(modn) used for decryption.

With n=3233,e=17,d=2753, signing M=100 gives S=1391. The public check gives 139117 mod 3233=100. Changing the message to 101 makes this check fail: the signature still verifies against 100.

The public key used for verification belongs to the signer. A verifier’s own key says nothing about a signature made with somebody else’s private key. Connecting a public key to its claimed owner requires authentication; a valid mathematical check establishes a relationship to that key.

A signature leaves the message public

Anyone with the public key can verify, so a signature supplies no confidentiality. Calling signing “private-key encryption” obscures this purpose and the different encodings used by practical encryption and signature schemes. If Alice wants a signed message to remain private to Bob, her signing key and Bob’s encryption key play separate roles. Bob decrypts with his private key and verifies using Alice’s public key.

Signatures also provide evidence that can support nonrepudiation: unlike a shared-secret check, public verification does not give every verifier the ability to sign. Attribution still depends on protecting the private key and establishing whose key it is.

Why multiplication permits a forgery

The bare RSA operation preserves multiplication. Given textbook signatures S1=M1d and S2=M2d modulo n, their product satisfies

(S1S2)e≡M1M2(modn).

For the running key, signatures on 2 and 3 are 1027 and 1857. Their product modulo 3233 is 2902, a valid signature on 6. Someone can construct it without knowing d. The forged message is a product of signed representatives; it need not be a message the signer ever approved.

There is another direct forgery. Choose a number S first, then set M=Se mod n. The pair passes the bare verification equation by construction. Choosing S=5 gives M=3086 for this key. It does not allow the attacker to choose any desired message, but it demonstrates that passing the raw equation alone is insufficient.

Hash and encode before signing

Practical signatures first hash the message to a fixed-length fingerprint, then apply a signature encoding and padding before the private operation. Verification computes the corresponding hash and checks the encoding. The hash handles messages of arbitrary length; the full signature scheme blocks these algebraic forgeries. A product of two encoded representatives is not generally the required encoding of the hash of the desired message.

Signatures can authenticate the public values in a Diffie–Hellman exchange. Each party can then check who supplied the value before treating the resulting shared key as belonging to that party.

Key Takeaways

  • Textbook RSA signs with d and verifies with the signer’s public exponent e.
  • A signature checks origin and integrity; it does not hide the message.
  • Multiplying textbook signatures yields a signature on the product of their message representatives.
  • Choosing a signature first creates another raw-equation forgery.
  • Practical signatures hash and encode the message before the RSA operation.
  • Authentication connects a verification key to the person or service it identifies.
5

Agree on a shared secret key with Diffie–Hellman

Diffie–Hellman builds a shared secret from public modular powers. To understand its choice of base, you first need the cycle length of a residue and the meaning of a discrete logarithm. You will follow both parties’ computations, identify what an eavesdropper would need to solve, and see why authentication is also necessary. ElGamal then applies the same shared-power idea to mask and recover a message.

5.1 Find orders, primitive roots and discrete logarithms

Powers of a coprime residue cycle back to 1. The cycle length explains which bases reach every nonzero residue and why recovering an exponent is a different problem from computing a power.

Find the order

For gcd⁡(a,n)=1, the order ord⁡n(a) is the smallest positive integer r with ar≡1(modn). Euler guarantees that such an exponent exists. Modulo 11, the powers of 3 are 3,9,5,4,1, so the order is 5. The powers of 2 are 2,4,8,5,10,9,7,3,6,1, giving order 10.

If am≡1, divide m by the order: m=qr+s with 0≤s<r. Then am≡(ar)qas≡as. A positive remainder s would contradict the minimality of r, so s=0. Thus the order divides every exponent returning the base to 1. In particular, r∣φ(n), and for a prime modulus r∣p−1.

Recognize a primitive root

A primitive root modulo a prime p has order p−1. Its powers reach all nonzero residues exactly once before repeating. The base 2 is a primitive root modulo 11; the base 3 is not. Every prime has primitive roots, and there are φ(p−1) of them. Modulo 11 they are 2, 6, 7 and 8, a total of φ(10)=4.

To test a candidate g≢0(modp), factor p−1. For each distinct prime divisor q, check

g(p−1)/q≢1(modp).

If the order were a proper divisor of p−1, it would divide at least one of these smaller exponents. Passing every check therefore forces full order. Zero must be excluded first: its powers are never 1, but it has no multiplicative order.

For p=23, the relevant prime divisors of 22 are 2 and 11. Since 511≡22 and 52≡2(mod23), neither check gives 1. Hence 5 is a primitive root modulo 23.

Reverse a modular power

For a primitive root g modulo p and nonzero y, the discrete logarithm is the unique exponent 0≤k≤p−2 with gk≡y(modp). Modulo 11, log⁡29=6 because 26≡9. Exponents are determined modulo the base’s order; the range selects one representative.

These logarithms are not obtained by ordinary real logarithms. Modulo 11, the discrete logs to base 2 of 8, 9 and 10 are 3, 6 and 5. Increasing the target by 1 does not produce a small predictable change in its discrete log.

Repeated squaring computes gk mod p quickly even for large exponents. Recovering k from the result is hard for suitably chosen large parameters with known classical algorithms. Trying every exponent is feasible for 11 or 23, but not for a well-chosen cryptographic modulus. This computational difference underlies Diffie–Hellman.

Why the primitive-root tests are enough

Write N=p−1 and suppose the order d is a proper divisor of N. The integer N/d>1 has a prime divisor q. Therefore d∣N/q and gN/q≡1(modp). At least one test must fail for every proper order. Conversely, a result of 1 at any tested exponent proves that the order is smaller than N.

A discrete-logarithm range removes a different ambiguity. If gu≡gv(modp) with u≥v, cancellation gives gu−v≡1. Thus the order divides u−v. For a primitive root, two different exponents in 0≤k≤p−2 cannot differ by p−1, giving uniqueness there. In particular, the target residue 1 has representative logarithm 0, while exponent p−1 names the same power outside that range.

Key Takeaways

  • The order is the smallest positive exponent returning a coprime base to 1.
  • The order divides every return exponent, including the totient.
  • A primitive root modulo a prime has order p−1.
  • Test nonzero primitive-root candidates using the distinct prime divisors of p−1.
  • A discrete logarithm recovers an exponent from a modular power.

5.2 Run and analyze the Diffie–Hellman key exchange

Diffie–Hellman key exchange lets two parties derive the same secret from values exchanged publicly. It agrees on a key; it does not itself encrypt their message.

Exchange powers, keep exponents secret

Alice and Bob publicly choose a prime p and a base g of large order. Alice chooses a secret a and sends A=ga mod p. Bob chooses a secret b and sends B=gb mod p. Alice computes K=Ba mod p; Bob computes K=Ab mod p. The values agree because

Ba≡(gb)a=gab=(ga)b≡Ab(modp).

Neither secret exponent is sent. The shared number is used to derive a key for symmetric encryption.

For p=23,g=5,a=6,b=15, Alice sends A=56 mod 23=8 and Bob sends B=515 mod 23=19. Their calculations give 196 mod 23=2 and 815 mod 23=2. An independent check uses ab=90≡2(mod22), so 590≡52≡2(mod23).

State the outsider’s problem precisely

Eve sees p,g,A,B. Computing gab from these is the Diffie–Hellman problem. Finding a discrete logarithm, such as recovering a from A, is sufficient: Eve could then compute Ba. This is a sufficient attack route, not an equivalence proof between the two problems.

Multiplying the public values gives AB≡ga+b, not gab. In the example, 8⋅19≡14(mod23), different from the shared value 2. With these small parameters Eve can simply enumerate powers; large, well-chosen parameters make that route infeasible with known classical methods.

Choose a base with enough possible powers

A large prime alone is insufficient. Modulo 23, the base g=22≡−1 has order 2. Its powers, and therefore possible shared values, are limited to 1 and 22. Cryptographic choices use large-order bases, commonly of large prime order. Elliptic-curve exchanges such as X25519 use a different representation to obtain comparable classical security with shorter keys. Shor’s algorithm threatens both classic RSA and discrete-logarithm exchanges on a sufficiently large quantum computer.

Authenticate the exchanged values

An active attacker can replace Alice’s and Bob’s public values and run a separate exchange with each. The attacker then knows both resulting keys and relays messages between them. This man-in-the-middle attack does not require solving the passive eavesdropper’s number-theory problem. Authentication, such as signatures on the exchange values tied to the parties, prevents undetected replacement.

Use the same idea for ElGamal encryption

Bob publishes B=gb mod p. Alice chooses a fresh secret k and sends c1=gk mod p and c2=MBk mod p. Bob computes c1b=gkb and removes that factor using its inverse.

For p=23,g=5,B=19,M=7,k=3, c1=10, Bk≡5 and c2=12. Bob gets 1015≡5; its inverse is 14, and 12⋅14≡7(mod23) recovers the message. The fresh exponent supplies the shared masking factor for this encryption.

Key Takeaways

  • The exchanged values are public powers; the exponents stay secret.
  • Both parties reach gab mod p by raising the received value to their own exponent.
  • Computing a discrete logarithm is sufficient to break the classic exchange.
  • A small-order base restricts the possible keys even when the prime is large.
  • Authentication prevents an attacker from substituting exchange values.
  • ElGamal masks a message with a shared power and removes it with a modular inverse.

Number Theory and Cryptography examples

5 Walkthroughs

1

Combine remainder conditions

13 steps
Build a CRT solution, prove its uniqueness and handle shared factors by substitution.
  1. 1
    IntroductionOne integer, several remainders

    A remainder condition describes infinitely many integers. Combining conditions can identify one class with a larger period. For pairwise coprime moduli, the Chinese remainder theorem guarantees a solution for every list of remainders.

    We will solve one system with moduli 3, 5 and 7, then change to shared-factor moduli to see when a system can fail. Each final answer needs both a representative and its period.

  2. 2
    ExplanationCheck every pair

    Take x≡2(mod3), x≡3(mod5) and x≡2(mod7). The moduli are pairwise coprime, and their product is M=105.

    Checking only the gcd of the whole list would be insufficient. For example, 6, 10 and 15 have overall gcd 1, yet every pair shares a factor. The product construction needs inverses for each component, which is why the pairwise condition matters.

  3. 3
    ExampleMake three independent contributions

    Divide 105 by each modulus to obtain the partial products 35, 21 and 15. Find their inverses in their own component moduli: 35−1≡2(mod3), 21−1≡1(mod5) and 15−1≡1(mod7).

    Multiplying a partial product by its inverse makes it 1 in its own component. It is already 0 in every other component because it contains those other moduli as factors.

  4. 4
    ExampleWeight and add the contributions

    Attach the requested remainders to their contributions:

    x=2⋅35⋅2+3⋅21+2⋅15=233.

    Reduce modulo 105 to get x≡23(mod105). Check 23 directly: its remainders modulo 3, 5 and 7 are 2, 3 and 2. The integer 233 also works; reducing it selects the representative between 0 and 104, without discarding the other solutions.

  5. 5
    Key InsightExplain the unique class

    Suppose two integers satisfy the three conditions. Their difference is divisible by 3, 5 and 7. Since these factors are pairwise coprime, the difference is divisible by 105.

    That proves uniqueness modulo 105. It does not say only one integer works: the full set is 23+105t for integer t.

  6. 6
    ChallengeReconstruct a new pair

    Solve x≡2(mod5) and x≡4(mod7). Give the whole class.

    ---reveal---

    Write x=2+5t. Then 5t≡2(mod7) gives t≡6(mod7), so x≡32(mod35). The moduli are coprime, so 35 is the period. Reporting only 32 would leave out all other members of the solution class.

  7. 7
    ExampleCarry the parameter forward

    Now solve x≡3(mod4), x≡5(mod9) and x≡2(mod5) by substitution. Write x=3+4t.

    The second condition gives 4t≡2(mod9). Multiplying by inverse 7 gives t≡5(mod9). Keep its parameter: t=5+9u, so x=23+36u. Setting x=23 permanently would lose the freedom needed to meet the third condition.

  8. 8
    ExampleImpose the final remainder

    Substitute x=23+36u into the condition modulo 5. It becomes 3+u≡2(mod5), giving u≡4(mod5).

    Thus x≡23+36⋅4=167(mod180). The modulus has grown from 4 to 36 and finally to 180 as each coprime condition is added. Reducing 167 modulo the three original moduli gives 3, 5 and 2.

  9. 9
    ExplanationShared factors must agree

    For x≡a(modm) and x≡b(modn), the gcd must divide a−b. This says the two conditions must agree on the part of their moduli that they share.

    For remainders 3 modulo 6 and 5 modulo 8, the gcd is 2 and both remainders are odd. The conditions are compatible. Their solution class has period lcm⁡(6,8)=24, not the product 48.

  10. 10
    ExampleDivide the whole congruence

    Set x=3+6t in the shared-factor example. The second condition gives 6t≡2(mod8). Divide coefficient, right side and modulus by 2:

    3t≡1(mod4).

    The inverse of 3 modulo 4 is 3, so t≡3(mod4) and x≡21(mod24). Dividing without reducing the modulus would describe a different, overly restrictive condition.

  11. 11
    ChallengeDecide whether a system is possible

    Can an integer satisfy x≡2(mod8) and x≡5(mod12)? Explain before trying a construction.

    ---reveal---

    No. The gcd is 4, but it does not divide 5−2=3. The first condition implies remainder 2 modulo 4; the second implies remainder 1. No integer has both remainders. An overall search or modular inverse calculation cannot remove that conflict.

  12. 12
    ChallengeSolve a bounded counting problem

    A positive collection has fewer than 60 items. Grouping by 4 leaves 1 over; grouping by 9 leaves 7 over. How many items are there?

    ---reveal---

    Write x=1+4t. Then 4t≡6(mod9) gives t≡6, so x≡25(mod36). The only positive member below 60 is 25; the next is 61. The congruences determine the class, and the bound selects the count.

  13. 13
    RecapCheck both the class and its period

    For coprime moduli, CRT constructs a solution and proves uniqueness modulo the product. Substitution reaches the same class by preserving an integer parameter through each condition.

    Shared factors require agreement modulo the gcd and give an lcm period. Before accepting an answer, reduce its representative in every original modulus and check that the stated period preserves all the conditions. Apply any interval restriction to the completed class.

2

Compute powers and interpret Fermat tests

14 steps
Use binary powers, prove Fermat’s theorem and distinguish a compositeness witness from a passing test.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionKeep the power small
  2. 2
    ExampleUse the binary exponent
  3. 3
    ExampleComplete the squaring chain
  4. 4
    ExampleMultiply the selected entries
  5. 5
    Key InsightCount operations from bits
  6. 6
    ChallengeApply the method independently
  7. 7
    ExplanationA prime gives a return exponent
  8. 8
    ExampleShorten a power and obtain an inverse
  9. 9
    ChallengeCheck the conditions before reducing
  10. 10
    ExplanationTurn a failure into a certificate
  11. 11
    ExplanationA pass leaves a gap
  12. 12
    ChallengeInterpret two test reports
  13. 13
    ChallengeConnect the theorem to the test
  14. 14
    RecapSeparate calculation from conclusion
3

Count invertible residues and combine power theorems

12 steps
Derive the totient formulas, prove Euler’s theorem and solve powers with CRT.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionCount before using a power theorem
  2. 2
    ExplanationRemove multiples of the prime
  3. 3
    ExampleMultiply across coprime factors
  4. 4
    ChallengeCalculate a totient from its factors
  5. 5
    ExplanationRearrange only the invertible residues
  6. 6
    ExampleUse the return exponent
  7. 7
    ChallengeReject an invalid shortcut
  8. 8
    ExampleSplit a power into prime moduli
  9. 9
    ExampleJoin the component results
  10. 10
    ChallengeHandle a noncoprime base locally
  11. 11
    ChallengeChoose both exponent moduli
  12. 12
    RecapKeep each condition with its theorem
4

Build an RSA key and test what it guarantees

17 steps
Generate a key, prove all-message recovery and examine why practical encryption and signatures add encoding.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionSeparate public and private operations
  2. 2
    ExplanationA public operation needs a trapdoor
  3. 3
    ChallengeChoose the recipient’s key
  4. 4
    ExampleForm the modulus and totient
  5. 5
    ExampleFind the inverse exponent
  6. 6
    ChallengeCheck a proposed smaller key
  7. 7
    ExampleEncrypt and reverse a representative
  8. 8
    ExplanationProve recovery for coprime messages
  9. 9
    Key InsightProve recovery for every residue
  10. 10
    ExampleDecrypt in smaller components
  11. 11
    ChallengeFind the missing proof case
  12. 12
    ExampleFind what a small ciphertext reveals
  13. 13
    ExplanationUse the signer’s public key
  14. 14
    ExampleMultiply signatures to expose a forgery
  15. 15
    ChallengeRecognize a pair created backward
  16. 16
    ChallengeAssign four key operations
  17. 17
    RecapDistinguish the guarantees
5

Agree on a secret through public powers

14 steps
Find the base’s order, follow both sides of Diffie–Hellman and remove an ElGamal mask.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionCombine secrets without transmitting them
  2. 2
    ExplanationFind the first return to one
  3. 3
    ExampleTest for the full cycle
  4. 4
    ExplanationRecover an exponent in a small system
  5. 5
    ChallengeCheck an order and a root
  6. 6
    ExampleSend public powers
  7. 7
    ExampleReach the same shared value
  8. 8
    ExplanationState Eve’s task
  9. 9
    ChallengeCompute a different exchange
  10. 10
    ConnectionPrevent substituted exchange values
  11. 11
    ExampleBuild an ElGamal mask
  12. 12
    ExampleRemove the shared factor
  13. 13
    ChallengeDistinguish two ways an exchange can fail
  14. 14
    RecapMatch each tool to its purpose

Number Theory and Cryptography practice questions

50 Practice Questions in 5 sets

Set 1: Remainders, powers and key roles10 Practice Questions

Question 1 of 10

Solve x≡1(mod4), x≡2(mod5) and x≡3(mod7). Give the complete solution class.
  1. x≡7(mod140)
  2. x≡17(mod140)
  3. x≡17(mod20)
  4. x≡12(mod140)
Show answerHide answer
Answer: B
The first two conditions give x=17+20t. Substituting into the third gives 3+6t≡3(mod7), hence t≡0(mod7) and x≡17(mod140). Keeping modulus 20 would include values such as 37 that fail the condition modulo 7.

Question 2 of 10

Solve x≡2(mod6) and x≡5(mod9).
  1. x≡14(mod54)
  2. x≡5(mod18)
  3. The system has no solution.
  4. x≡14(mod18)
Show answerHide answer
Answer: D
The gcd is 3, which divides the difference of the remainders, so the system is compatible. Substituting x=2+6t gives 6t≡3(mod9) and t≡2(mod3), hence x≡14(mod18). Modulus 54 would omit solutions because the least period is the lcm, 18.

Question 3 of 10

Compute 313 mod 17.
  1. 12
  2. 3
  3. 16
  4. 13
Show answerHide answer
Answer: A
Use 13=8+4+1. Squaring modulo 17 gives 32≡9, 34≡13 and 38≡16, so 313≡16⋅13⋅3≡12. Multiplying every squared power instead would include exponent 2 and compute the wrong total exponent.

Question 4 of 10

What is the multiplicative inverse of 4 modulo 13?
  1. 9
  2. 3
  3. 10
  4. 4
Show answerHide answer
Answer: C
4⋅10=40≡1(mod13), so 10 is the multiplicative inverse. The value 9 is the additive inverse: it makes 4+9≡0, not a product of 1.

Question 5 of 10

A test of 15 gives 214≡4(mod15). What conclusion follows?
  1. 15 is probably prime, with base 2 passing.
  2. 15 is composite, with 4 as a prime factor.
  3. 15 is composite, with base 2 as a witness.
  4. 15 needs a second base before rejection.
Show answerHide answer
Answer: C
If 15 were prime, Fermat’s theorem would require the tested residue to be 1. Its residue is 4, so base 2 is a witness proving compositeness. A second test is unnecessary after one failure, and the residue itself need not be a factor of the candidate.

Question 6 of 10

Find φ(45).
  1. 32
  2. 24
  3. 30
  4. 16
Show answerHide answer
Answer: B
Factor 45=32⋅5 and apply the prime-power formula: φ(9)=6 and φ(5)=4. The factors 9 and 5 are coprime, so their totients multiply to 24. Using (3−1)2 for the prime-square totient would incorrectly give 16 for the final product.

Question 7 of 10

What is the last digit of 342?
  1. 9
  2. 3
  3. 1
  4. 7
Show answerHide answer
Answer: A
The base 3 is coprime to 10, and φ(10)=4. Reduce the exponent to 42 mod 4=2, giving 342≡32=9(mod10). A remainder of zero would give 1, but 42 is not a multiple of the exponent period 4.

Question 8 of 10

Bob wants to send an RSA-encrypted message that only Alice can decrypt. Whose key does Bob use to encrypt?
  1. Alice’s private key
  2. Bob’s public key
  3. Bob’s private key
  4. Alice’s public key
Show answerHide answer
Answer: D
Bob encrypts with Alice’s public key because Alice is the recipient. Bob’s public key would instead require Bob’s private key for decryption.

Question 9 of 10

An RSA key uses p=5, q=11 and e=3. What is the least positive private exponent modulo the totient?
  1. 37
  2. 27
  3. 14
  4. 18
Show answerHide answer
Answer: B
The totient is (5−1)(11−1)=40. The private exponent must satisfy 3d≡1(mod40), and 3⋅27=81=2⋅40+1. The value 37 instead inverts 3 modulo the message modulus 55, which is not the exponent modulus required in this construction.

Question 10 of 10

What is the order of 4 modulo 7?
  1. 3
  2. 6
  3. 2
  4. 4
Show answerHide answer
Answer: A
The powers 4,2,1(mod7) first reach 1 at exponent 3. Fermat’s return at exponent 6 is later; order means the smallest positive return exponent.
Set 2: Apply the theorems to public-key arithmetic10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

RSA uses n=55,e=3,d=27. What message representative is recovered from ciphertext 20?
  1. 20
  2. 5
  3. 15
  4. 25
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

For public key n=77,e=7, what message representative does textbook signature 58 verify against?
  1. 58
  2. 16
  3. 43
  4. 9
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

Given 46≡1(mod13), why does 4 fail to be a primitive root modulo 13?
  1. Its twelfth power is 1 modulo 13.
  2. Its square is nonzero modulo 13.
  3. Its sixth power is already 1 modulo 13.
  4. Its fourth power is 9 modulo 13.
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

Diffie–Hellman uses p=29,g=2 and secret exponents a=5,b=9. What shared value do both parties compute?
  1. 28
  2. 19
  3. 3
  4. 21
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

Compute 350 mod 35.
  1. 4
  2. 9
  3. 2
  4. 6
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

For RSA primes 7 and 13 with public exponent 5, find the least positive inverse of 5 modulo the totient.
  1. 29
  2. 73
  3. 17
  4. 43
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

Solve x≡4(mod5) and x≡1(mod7).
  1. x≡9(mod35)
  2. x≡24(mod35)
  3. x≡29(mod35)
  4. x≡34(mod35)
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

For exponent 45, how many modular multiplications does optimized repeated squaring use, counting squarings and omitting the initial copy?
  1. 8 operations
  2. 9 operations
  3. 7 operations
  4. 10 operations
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

Compute 673 mod 19.
  1. 1
  2. 9
  3. 15
  4. 6
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

An RSA modulus is n=143 and its totient is 120. What are its two prime factors?
  1. 7 and 19
  2. 11 and 13
  3. 5 and 29
  4. 3 and 47
Show answerHide answer

Save this lesson to see this answer.

Set 3: Check boundaries, proofs and attacks10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

Solve x≡5(mod8) and x≡9(mod12).
  1. x≡21(mod96)
  2. x≡13(mod24)
  3. The system has no solution.
  4. x≡21(mod24)
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

A calculation of b43 selects exponents 32, 8 and 1 from a repeated-squaring table. What additional table entry is needed?
  1. b4
  2. b2
  3. b16
  4. b8
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

Classify 1105=5⋅13⋅17 using Korselt’s criterion.
  1. It is Carmichael: squarefree, with 4, 12 and 16 dividing 1104.
  2. It is not Carmichael: 5, 13 and 17 do not all divide 1104.
  3. It is not Carmichael: the three prime factors are different.
  4. It is Carmichael: three distinct prime factors are sufficient.
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

What is the last digit of 335?
  1. 3
  2. 9
  3. 7
  4. 1
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

Compute 1423 mod 35.
  1. 14
  2. 1
  3. 4
  4. 21
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A method recovers a valid RSA private exponent from any public key of the usual two-prime form. What further task does this enable efficiently?
  1. Proving a polynomial lower bound on factoring.
  2. Solving unrelated discrete logarithms.
  3. Recovering secret keys of symmetric ciphers.
  4. Factoring each corresponding RSA modulus.
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

RSA uses n=91,e=5,d=29. Message 26 encrypts to 52. What does decryption return, and why?
  1. 26; Euler applies directly because every message is invertible.
  2. 26; the prime-modulus proof and CRT cover this message.
  3. 0; any message sharing a factor with the modulus is lost.
  4. 52; noninvertible messages remain at their ciphertext value.
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

With n=55,e=3, textbook signatures 3 and 8 verify against messages 27 and 17. What signature on message 19 can be forged by combining them?
  1. 11
  2. 19
  3. 24
  4. 44
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

Find the discrete logarithm of 12 to base 3 modulo 17, in the range 0 through 15.
  1. 13
  2. 4
  3. 12
  4. 8
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

Diffie–Hellman uses prime 31 but base 30. What are the possible shared values?
  1. Every nonzero residue modulo 31
  2. 1 and 30 only
  3. 0 and 30 only
  4. 1 and 15 only
Show answerHide answer

Save this lesson to see this answer.

Set 4: Combine computations with justification10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

What is the inverse of 11 modulo 36?
  1. 25
  2. 13
  3. 11
  4. 23
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

Compute 2173 mod 143.
  1. 8
  2. 19
  3. 6
  4. 14
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

Two integers meet the same remainder conditions modulo 4, 9 and 5. What is the least positive difference they can have?
  1. 180
  2. 18
  3. 45
  4. 90
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

Solve 6x≡9(mod15) together with x≡2(mod7).
  1. x≡9(mod105)
  2. x≡4(mod35)
  3. x≡9(mod35)
  4. x≡23(mod35)
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

Let p be prime and let a be divisible by p. What are ap mod p and ap−1 mod p, respectively?
  1. 0 and 1
  2. 0 and 0
  3. 1 and 0
  4. 1 and 1
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

Find φ(840).
  1. 96
  2. 240
  3. 384
  4. 192
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

RSA uses p=11,q=17,e=3. Compare private exponents 27 and 107: which recover every message representative?
  1. Both work; their public-exponent products are 1 modulo 80.
  2. Only 107 works; a totient inverse is always necessary.
  3. Only 27 works; the least exponent is uniquely valid.
  4. Neither works; 3 must be inverted modulo 187.
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

For n=65,e=5,d=5, what is recovered from ciphertext 30, and can Euler be applied directly to that ciphertext modulo 65?
  1. 10; Euler applies directly modulo 65.
  2. 30; a shared factor prevents decryption.
  3. 10; Euler cannot be applied directly.
  4. 0; the ciphertext is noninvertible.
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

An attacker chooses textbook signature S=2 for public key n=91,e=5. What message can the attacker pair with it to pass raw verification?
  1. 10
  2. 25
  3. 32
  4. 64
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

Diffie–Hellman uses p=31,g=3,A=19,B=17. Alice’s secret exponent is 4. Find the shared value and the product of the public values, modulo 31.
  1. Shared value 7; public product 13.
  2. Shared value 13; public product 7.
  3. Shared value 19; public product 13.
  4. Shared value 7; public product 5.
Show answerHide answer

Save this lesson to see this answer.

Set 5: Solve new systems and diagnose failures10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

RSA has n=143,e=7,d=103. Decrypt ciphertext 81.
  1. 9
  2. 42
  3. 3
  4. 75
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

Find the least nonnegative integer satisfying x≡1(mod8), x≡3(mod9) and x≡2(mod5).
  1. 17
  2. 57
  3. 129
  4. 273
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

An optimized repeated-squaring calculation uses a positive exponent with exactly three 1-bits. How many multiplications into the result are needed after the initial copy?
  1. 3 multiplications
  2. 1 multiplication
  3. 2 multiplications
  4. 4 multiplications
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

For 45=32⋅5, determine whether it is Carmichael and find 244 mod 45.
  1. Not Carmichael; the residue is 31.
  2. Carmichael; the residue is 1.
  3. Not Carmichael; the residue is 16.
  4. Carmichael; the residue is 31.
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

Find 6100 mod 40 and decide whether reducing 100 modulo φ(40) is justified by Euler’s theorem.
  1. 16; Euler justifies reduction for every integer base.
  2. 36; Euler does not justify that reduction.
  3. 0; Euler does not justify that reduction.
  4. 16; Euler does not justify that reduction.
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

Compute 334 mod 14.
  1. 13
  2. 3
  3. 9
  4. 1
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A textbook RSA public key has n=391,e=3. An intercepted ciphertext is 125. What message representative is immediately exposed, and what permits this recovery?
  1. 8; it needs reduction modulo the exponent.
  2. 125; the public operation fixes small inputs.
  3. 5; its unreduced cube is below the modulus.
  4. 3; the private exponent equals the public one.
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

An RSA public key has n=247 and e=5. Find the least positive private exponent modulo φ(n).
  1. 99
  2. 197
  3. 43
  4. 173
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A proposed RSA-like encryption uses n=77,e=6. Find the ciphertexts of messages 2 and 9. Can a private exponent recover every input?
  1. Both give 64; an inverse exponent recovers both.
  2. 2 gives 64 and 9 gives 16; an inverse exists.
  3. Both give 4; no inverse exponent recovers both.
  4. Both give 64; no inverse exponent recovers both.
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

ElGamal uses p=29,g=2, Bob’s private exponent 7 and ciphertext (c1,c2)=(3,21). What message is recovered?
  1. 12
  2. 9
  3. 20
  4. 24
Show answerHide answer

Save this lesson to see this answer.

Stuck on your own question? Homework Help

Key Terms

69 Key Terms, each with its definition

A

Authentication
Authentication establishes the claimed origin or identity of an exchange value so that undetected substitution can be rejected.
Signatures on Diffie–Hellman values can provide authentication when their verification keys are tied to the parties.

B

Back substitution
Back substitution solves a congruence system by expressing one condition with an integer parameter and inserting it into the next condition.
Back substitution writes x≡3(mod4) as x=3+4t, then inserts this into a remainder condition modulo 9.
Binary expansion
A binary expansion expresses an integer using digits 0 and 1, each place representing a power of 2.
The binary expansion 117=11101012 identifies five repeated-squaring results to multiply for a power with exponent 117.

C

Carmichael function
The Carmichael function gives the smallest common positive exponent returning every invertible residue to 1; for distinct primes, λ(pq)=lcm⁡(p−1,q−1).
The Carmichael function is 780 for modulus 3233, so RSA can use an inverse modulo 780 instead of modulo 3120.
Carmichael number
A Carmichael number is a composite that passes every Fermat test whose base is coprime to it.
The Carmichael number 561 passes every coprime-base Fermat test but is exposed by a base sharing one of its factors.
Chinese remainder theorem
The Chinese remainder theorem gives one solution class modulo the product for any remainder list with pairwise coprime moduli greater than 1.
The Chinese remainder theorem turns three remainder conditions whose moduli multiply to 105 into one class modulo 105.
Ciphertext
A ciphertext is the encrypted representation produced from a message; textbook RSA computes it as C=Me mod n.
Under an RSA key with public exponent 17, the ciphertext 2790 is produced from message representative 65.
Compatibility condition
A compatibility condition is the requirement that two prescribed remainders agree modulo the greatest common divisor of their moduli.
The compatibility condition fails for remainder 1 modulo 4 and remainder 2 modulo 6 because their parities differ.
Component congruence
A component congruence gives one remainder condition after a modulus is split into coprime factors.
The component congruence modulo 3 for 6100 mod 15 has remainder zero because the base is divisible by 3.
Coprimality
Coprimality means that two integers have greatest common divisor 1 and hence no shared prime factor.
Coprimality fails for 2 and 10, so Euler’s return-to-one claim cannot be applied to that base and modulus.
CRT decryption
CRT decryption performs RSA’s private power separately modulo the secret primes, then reconstructs the message modulo their product.
For an RSA key with primes 61 and 53, CRT decryption obtains residues 4 modulo 61 and 12 modulo 53 before reconstructing message 65.
CRT reconstruction
CRT reconstruction recovers one residue modulo a product from its specified remainders in pairwise coprime factor moduli.
CRT reconstruction combines remainders 14 modulo 17 and 17 modulo 23 into residue 201 modulo 391.
Cryptographic hash
A cryptographic hash maps a message of arbitrary length to a fixed-length fingerprint designed to resist attacks such as finding collisions.
An RSA signature scheme signs an encoding of a cryptographic hash instead of applying the private power to the raw message.

D

Deterministic encryption
Deterministic encryption always gives the same ciphertext for the same message under a fixed key, permitting comparison of encrypted guesses.
Textbook RSA is deterministic encryption, so an observer can compare encryptions of a short list of suspected messages.
Diffie–Hellman exchange
The Diffie–Hellman exchange derives shared key material by exchanging public powers and combining them with private exponents.
In the Diffie–Hellman exchange with prime 23 and base 5, public values 8 and 19 lead both parties to shared value 2.
Diffie–Hellman problem
The Diffie–Hellman problem asks for gab mod p given the public parameters and the two public powers ga,gb.
Recovering either secret exponent by a discrete logarithm is sufficient to solve the Diffie–Hellman problem.
Digital signature
A digital signature is a value created with a private signing key and checked with its public key to support origin and integrity checks.
Under one RSA key, the digital signature 1391 verifies against message 100, but changing the message to 101 makes the check fail.
Discrete logarithm
A discrete logarithm is an exponent solving gk≡y(modp), specified modulo the base’s order.
The discrete logarithm of 9 to base 2 modulo 11 is 6, since 26≡9(mod11).
Discriminant
The discriminant of t2−st+n is s2−4n and determines the square-root term in its quadratic formula.
For RSA modulus 3233 and prime sum 114, the discriminant is 64, giving the two factors 61 and 53.

E

ElGamal encryption
ElGamal encryption sends a public ephemeral power and a message multiplied by the resulting shared power, which the recipient removes.
An ElGamal encryption of 7 produces (10,12); removing the shared factor 5 from 12 recovers 7.
Euler’s theorem
Euler’s theorem states that aφ(n)≡1(modn) whenever the base a is relatively prime to n.
Euler’s theorem gives period 4 for powers of 7 modulo 10, allowing exponent 222 to be reduced to 2.
Euler’s totient
Euler’s totient φ(n) is the number of integers from 1 through n relatively prime to n.
Euler’s totient of 12 is 4 because its invertible residues are represented by 1, 5, 7 and 11.
Exponent period
An exponent period for a coprime base is a positive integer T such that aT≡1 modulo the chosen modulus.
An exponent period of 12 works for powers of 2 modulo 13, although smaller periods must be checked separately.
Exponent reduction
Exponent reduction replaces an exponent by its remainder modulo a valid period of the base.
Valid exponent reduction replaces 1000 by zero for powers of 3 modulo 100, using period 40.

F

Fermat pseudoprime
A Fermat pseudoprime to a base is a composite integer that satisfies the return-to-one congruence used in that base’s Fermat test.
The number 341 is a Fermat pseudoprime to base 2, so a successful base-2 test alone cannot certify it prime.
Fermat test
The Fermat test checks whether an−1≡1(modn) for a chosen base; failure proves the candidate composite.
The Fermat test rejects 91 at base 2 because its computed power has remainder 64 instead of 1.
Fermat witness
A Fermat witness is a base whose tested power is not congruent to 1, establishing that the candidate integer is composite.
Base 3 is a Fermat witness for 341, even though that same candidate passes a test at base 2.
Fermat’s little theorem
Fermat’s little theorem states that ap−1≡1(modp) for a prime p and a base a not divisible by p.
Fermat’s little theorem shortens exponent 100 to 4 when computing a nonzero base’s power modulo 13.

K

Key distribution problem
The key distribution problem is the challenge of establishing a shared secret between parties communicating over an observable channel.
Public-key methods address the key distribution problem before symmetric encryption protects the longer message.
Key generation
Key generation constructs a compatible public and private key, using secret primes and modular inversion in the RSA case.
RSA key generation checks the gcd of the public exponent with the totient before finding the private exponent.
Korselt’s criterion
Korselt’s criterion characterizes Carmichael numbers as squarefree composites with p−1∣n−1 for every prime divisor p.
Korselt’s criterion checks divisibility of 560 by 2, 10 and 16 for the distinct prime factors of 561.

L

Least common multiple
The least common multiple is the smallest positive integer divisible by all the given integers.
The least common multiple of 6 and 8 is 24, the least period of a compatible system with those moduli.
Least nonnegative residue
The least nonnegative residue modulo a positive integer n is the unique representative of a congruence class between 0 and n−1.
The least nonnegative residue of 21000 modulo 1001 is 562, which meets the conditions modulo each of the three prime factors of 1001.
Left-to-right exponentiation
Left-to-right exponentiation processes binary bits from the leading bit, squaring for each later bit and multiplying by the base for a 1.
Left-to-right exponentiation starts at 5 for the leading 1-bit in the computation of 5117 mod 391.
Linear congruence
A linear congruence has the form ax≡b(modm) and is solvable exactly when gcd⁡(a,m) divides b.
The linear congruence 6t≡2(mod8) is reduced by dividing its coefficient, right side and modulus by 2.

M

Man-in-the-middle attack
A man-in-the-middle attack replaces exchange messages so an attacker forms separate shared keys with the two intended parties.
A man-in-the-middle attack on plain Diffie–Hellman succeeds through substitution, without breaking a discrete logarithm.
Message representative
A message representative is the integer on which an RSA operation acts, selected in the range 0≤M<n.
The message representative 67 is what remains when an attempted input of 3300 is reduced modulo 3233.
Modular cancellation
Modular cancellation removes a common invertible factor from a congruence by multiplying both sides by that factor’s modular inverse.
Modular cancellation removes the product of the nonzero residues in the proof of Fermat’s theorem.
Modular exponentiation
Modular exponentiation computes the residue of an integer power modulo a specified modulus without requiring the full ordinary power.
RSA uses modular exponentiation for its public and private operations, even when the exponents are very large.
Multiplicative function
A multiplicative function on positive integers satisfies f(mn)=f(m)f(n) whenever m and n are coprime.
The totient is a multiplicative function, so φ(1001)=φ(7)φ(11)φ(13)=720.
Multiplicative order
The multiplicative order of an invertible residue is the smallest positive exponent returning it to 1 modulo the chosen modulus.
The multiplicative order of 3 modulo 11 is 5 because its first five powers end with its first return to 1.

N

Nonrepudiation
Nonrepudiation is support for holding a signer accountable through evidence tied to a private key, with reliable key ownership and protection.
Public verification supports nonrepudiation because a verifier does not need the secret information required to create signatures.

O

One-way function
A one-way function is a function that is efficient to compute but computationally difficult to reverse on the relevant inputs.
The proposed one-way function in RSA maps message representatives to modular powers using the public key.

P

Pairwise coprime moduli
Pairwise coprime moduli are moduli for which every two distinct members have greatest common divisor 1.
The pairwise coprime moduli 3, 5 and 7 allow the CRT construction with total modulus 105.
Partial product
A CRT partial product is the product of all moduli except the component’s own modulus.
For total modulus 105 and component modulus 3, the partial product is 35, which is invertible modulo 3.
Power tower
A power tower is an exponentiation whose exponent is itself a power, with the upper power evaluated before the outer one.
For the power tower 777 modulo 10, the upper exponent is first evaluated modulo 4.
Prime power
A prime power is an integer of the form pk, where p is prime and k is a positive integer.
The prime powers 8 and 3 form coprime factors of 24, allowing a condition modulo 24 to be split.
Prime-power decomposition
A prime-power decomposition writes an integer as a product of powers of distinct primes, giving pairwise coprime component moduli.
The prime-power decomposition 100=4⋅25 permits separate calculations modulo 4 and modulo 25.
Primitive root
A primitive root modulo a prime p is a nonzero residue with order p−1, whose powers reach every nonzero residue.
The primitive root 2 modulo 11 has ten different nonzero powers before its cycle repeats.
Primitive-root test
The primitive-root test checks a nonzero candidate modulo prime p at exponents (p−1)/q for each distinct prime divisor q of p−1.
The primitive-root test for 5 modulo 23 checks exponents 11 and 2, neither of which gives remainder 1.
Private exponent
The private exponent d is the secret RSA power chosen so that ed≡1 modulo the totient or the relevant Carmichael value.
With public exponent 17, the private exponent 413 works with modulus 3233 because 17⋅413≡1(mod780).
Probable prime
A probable prime to a Fermat base is a candidate that passes that base’s test, while its actual primality remains unsettled by the pass.
The composite integer 341 is a probable prime to base 2 because it satisfies the tested congruence.
Public exponent
The public exponent e is the published RSA power used for encryption or verification and chosen coprime to the exponent modulus.
In an RSA key whose totient is 3120, the public exponent 17 has inverse 2753 modulo 3120.
Public-key cryptography
Public-key cryptography uses a published key and a matching secret key so that public operations do not expose private operations.
RSA illustrates public-key cryptography by allowing anyone to encrypt for a recipient without knowing the private exponent.

R

Randomized padding
Randomized padding transforms a message using randomness before encryption so that repeated messages need not produce the same ciphertext.
RSA encryption uses randomized padding such as OAEP to address the predictability of its bare modular-power formula.
Reduced residue system
A reduced residue system contains one representative of each residue class coprime to the modulus, so every represented class is invertible.
The reduced residue system 1,5,7,11 has four members modulo 12 and is permuted by multiplication by 5.
Repeated squaring
Repeated squaring builds powers with exponents 1, 2, 4, 8 and so on, then combines entries selected by the exponent’s binary digits.
Repeated squaring computes 5117 mod 391 by selecting the entries for exponents 64, 32, 16, 4 and 1.
Residue permutation
A residue permutation rearranges a list of residues without adding, losing or repeating a member.
Multiplication by 3 gives the residue permutation 3,6,2,5,1,4 of the nonzero residues modulo 7.
RSA modulus
An RSA modulus is the public integer n=pq formed from two distinct secret primes in the basic two-prime construction.
The RSA modulus 3233 is public, while its factors 61 and 53 remain private.

S

Shared secret
A shared secret is a value known to the intended parties but hidden from outsiders, used as key material after a key exchange.
In a Diffie–Hellman exchange, the shared secret 2 comes from exponent multiplication, not from the product 14 of the public values.
Signature forgery
A signature forgery is a valid-looking message-signature pair produced without the signer’s authorization for that message.
Multiplying textbook signatures on 2 and 3 gives a signature forgery on their product 6 under the same RSA key.
Signature verification
Signature verification checks a signature against a message using the signer’s public key and the signature scheme’s validation rules.
Textbook signature verification raises 1391 to exponent 17 modulo 3233 and compares the result with 100.
Simultaneous congruences
Simultaneous congruences are remainder conditions that the same integer must satisfy together.
Sunzi’s classic remainder problem poses simultaneous congruences requiring remainders 2, 3 and 2 modulo 3, 5 and 7.
Solution class
A solution class contains every integer congruent to a chosen representative modulo its period.
The solution class 23+105t includes negative as well as positive integers as t ranges over integers.
Squarefree integer
A squarefree integer has no repeated prime factor; equivalently, no square of a prime divides it.
Korselt’s criterion requires a squarefree integer, so the repeated factor in 45=32⋅5 rules it out.
Squaring
Squaring multiplies a number by itself; when applied to a power, it doubles that power’s exponent.
In a modular table, squaring the residue of b4 produces the residue of b8 after reduction.
Symmetric cryptography
Symmetric cryptography encrypts and decrypts data using a secret key shared by the parties.
A shift cipher illustrates symmetric cryptography because both encryption and decryption depend on the same shift.

T

Totient product formula
The totient product formula is φ(n)=n∏p∣n(1−1/p) over distinct prime divisors.
The totient product formula uses corrections for 2, 3 and 5 when applied to 360, despite repeated prime factors.
Trapdoor function
A trapdoor function is a one-way function for which secret information makes the otherwise difficult inverse operation efficient.
RSA is designed as a trapdoor function whose private exponent makes the public modular power reversible.

About this lesson

By StudeliReport a mistake

Make your own Study Materials

Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.

Get Started