Prime Density and the Chinese Remainder Theorem
Prime Distribution and Cryptography
Prime counts and density
The prime-counting function π(x) counts the prime numbers less than or equal to x. For example, π(10)=4, because the primes up to 10 are 2,3,5, and 7.
The proportion of integers up to x that are prime is xπ(x). This proportion is called the density of primes up to x. A useful estimate is that this density is on the order of log2x1, where log2 is the logarithm to base 2. Equivalently, the number of primes up to x is on the order of log2xx.
The logarithmic estimate was conjectured by Gauss after he examined tables of primes. The elementary argument developed here gives constant-factor bounds of the general form
with small-range and additive-error details depending on the precise version of the bounds. In particular, the estimates show that primes become less frequent as numbers grow, but remain numerous enough for many computational applications.
The key conclusion is that π(x) grows roughly like log2xx, rather than like x.
Three lemmas used to estimate the number of primes
Lemma 1: A lower bound on the central binomial coefficient
For a positive integer n,
The binomial theorem gives
Among the 2n+1 terms in this sum, the central term (n2n) is the largest. The largest term in a sum is at least the average of its terms, so
Thus, the central binomial coefficient is large: it is at least the average size of all the binomial coefficients in its row.
Lemma 2: Prime-power factors of the central binomial coefficient
For every prime p, the full power of p dividing (n2n) is at most 2n. In other words, if pvp is the largest power of p dividing this binomial coefficient, then
The binomial coefficient can be written as
This quotient compares factors from the interval above n with factors from 1 through n. Prime powers appearing in the denominator are largely matched by corresponding divisibility among the numerator factors. The prime-power contribution that remains for any one prime is bounded by the size of the numerator range, namely 2n.
Consequently, although (n2n) itself can be very large, no single prime contributes a power larger than 2n to its factorization.
Lemma 3: The product of primes up to n
For every positive integer n,
This is proved by induction, separating the odd and even cases.
Odd case
Suppose n=2m+1. Split the primes up to 2m+1 into two groups:
Primes p≤m+1.
Primes m+1<p≤2m+1.
By the induction hypothesis, the product of the first group is at most 4m+1.
Each prime in the second group divides (m2m+1). Indeed,
and a prime greater than m+1 appears among the numerator factors but not among the denominator factors. Since the primes in this group are distinct, their product is at most the binomial coefficient.
The two central terms in the binomial expansion of (1+1)2m+1 are equal and largest. Their sum is at most the sum of all the terms, which is 22m+1. Therefore,
Combining the two groups gives
Even case
If n=2m, then 2m is not prime, so the product of primes up to 2m is the same as the product of primes up to 2m−1. Applying the odd case gives
The odd and even cases complete the induction.
Estimating the number of primes up to x
Upper bound
Consider the primes in the interval (x,x]. Their number is
Each such prime is greater than x. Therefore, their product is at least
By Lemma 3, the product of all primes up to x is at most 4x. The product of just the primes in (x,x] cannot be larger, so
Taking base-2 logarithms yields
and hence
There are at most x integers up to x, so π(x)≤x. Thus,
For the relevant range, x≤log2xx, giving the convenient estimate
This improves on the simple observation π(x)≤x: the number of primes is substantially smaller than the number of integers up to x.
Lower bound
Every prime factor of (n2n) is at most 2n. By Lemma 2, the contribution from each distinct prime factor is at most 2n, and there are at most π(2n) such primes. Therefore,
Lemma 1 provides a lower bound for the same binomial coefficient:
Combining the bounds and taking base-2 logarithms gives
Thus,
This is approximately log2(2n)2n, apart from a relatively small correction. For general x, an even integer can be chosen close to x, producing a corresponding lower estimate of order log2xx, with a small additive error.
Together, the upper and lower estimates show that
meaning that the number of primes is bounded above and below by constant multiples of log2xx for sufficiently large x.
Prime-containing intervals
The estimates on π(x) can be used to study intervals containing primes. The number of primes in (x,6x] is
Lower-bounding the first term and upper-bounding the second can show that this difference is positive for sufficiently large x. The coarse constant-factor bounds require care with logarithms and small values of x‘;theydonotbythemselvesestablishtheclaimforeveryx$ without additional checking.
A stronger classical result is Bertrand’s postulate, proved by Chebyshev: for every integer n>1, there is a prime between n and 2n. This is a much sharper guarantee than merely finding a prime within a constant multiple of n.
There cannot be a fixed number c such that every interval (x,x+c] contains a prime. Prime gaps can be arbitrarily long, so some intervals of any fixed length contain no prime.
A famous unproved conjecture, often called Legendre’s conjecture, states that there is a prime between every pair of consecutive squares:
The interval’s length is 2n+1, which is small compared with its starting point n2. Bertrand’s postulate does not establish this conjecture: an interval from n2 to 2n2 is far wider than the interval between consecutive squares.
Chinese remainder theorem
For a system of congruences in one variable, such as
if the moduli ni are pairwise coprime, the Chinese remainder theorem guarantees a solution that is unique modulo the product of the moduli. This result is useful in number theory and computation because it allows a problem modulo a large number to be represented through several congruences modulo smaller, coprime numbers.
Cryptography: communicating over an insecure channel
Cryptography concerns methods for communicating messages so that intended recipients can understand them while adversaries observing the communication cannot. A channel may be a physical object, a wire, a wireless transmission, or a storage device. It is considered insecure if an adversary can observe the information sent through it.
Two important communication concerns are:
Error correction: recovering or detecting information when a channel or storage medium introduces errors.
Security: preventing an adversary from understanding or exploiting the message.
Error-correcting codes address the first concern. They are essential because real devices and communication channels can introduce errors. Algebraic methods are often used to detect or correct corrupted data. Cryptography addresses the second concern.
Participants and message representation
A typical model uses three participants:
Alice, who sends a message.
Bob, who receives it.
Eve, an adversary who can observe the channel.
The message, called the plaintext and denoted M, can be represented as a string of bits. Text, numbers, punctuation, and other data can be encoded as binary strings.
An encryption algorithm uses a secret S and plaintext M to produce a ciphertext C:
Bob applies a corresponding decryption algorithm using the secret to recover the message:
Decryption must recover the intended plaintext uniquely and correctly. If the recovered message could be ambiguous or incorrect, the system would not be dependable.
Shared secrets
A basic way for Alice and Bob to keep a conversation private is for them to share a secret before communicating. They use that secret to encrypt and decrypt messages, while Eve observes only the ciphertext.
This approach makes the security of the system depend on several factors:
How difficult it is for Eve to discover the secret.
How the encryption algorithm uses the secret.
Whether patterns in the plaintext leak information about the secret.
Substitution ciphers
A substitution cipher replaces each letter with another letter according to a secret permutation of the alphabet. For example, a cyclic shift may map A to B, B to C, and so on, with Z mapped back to A. This particular shift is a form of the Caesar cipher.
Encryption applies the permutation π to the message:
Decryption applies the inverse permutation:
If the secret is a general permutation of the 26 letters, there are 26! possible keys. This may seem like a large search space, but a large key space alone does not guarantee practical security.
Frequency analysis
Natural languages are not arbitrary strings. Letters occur at unequal rates: for example, some letters are common in English, while others are rare. A monoalphabetic substitution preserves these frequency patterns, even though it changes which symbols represent which letters.
An adversary can use frequency analysis by examining ciphertext and comparing its letter frequencies with those typical of the language. Repeated words, common letter combinations, and context can provide further clues. With enough meaningful ciphertext, Eve may infer much of the substitution and use linguistic patterns to complete the recovery.
A cipher can have many possible keys and still be insecure if its ciphertext preserves recognizable structure from the plaintext.
For this reason, simple substitution ciphers are not practically secure. Modern cryptography uses more sophisticated mathematical methods, including ideas from number theory and algebra. Conversely, a long secret key is not by itself a proof of security: the encryption method must also resist attacks that exploit patterns or other information in the messages.

Ask anything
We've read this whole study set, so questions about it get the best answers.