II. Post-quantum Cryptography: B-2. LWE Cryptosystem
Published: Updated:
This post is based on The Beginner’s Textbook for Fully Homomorphic Encryption by Ronny Ko.
In this post, I provide a summary and review of “II. Post-quantum Cryptography: B-2. LWE Cryptosystem.”
B-2. LWE Cryptosystem
B-2.1 Setup
Key Notations
| Symbol | Meaning |
|---|---|
| $[0, t)$ | Plaintext Range |
| $[0, q)$, where $t<q$ | Ciphertext Range ($t$ is much smaller than $q$) |
| $S \in_R \mathbb{Z}_2^k$ | Secret key sampled uniformly at random (each entry in ${0,1}$) |
| $\Delta = \frac{q}{t}$ | Scaling factor of plaintext |
B-2.2 Encryption
1. Encryption Steps
1) Suppose we have a plaintext $m \in \mathbb{Z}_t$
2) Sample a random vector $A \in_R \mathbb{Z}_q^k$
→ This acts as a one-time public key
3) Sample a small noise $e \in \mathbb{Z}_q$
→ $e \sim \chi_{\sigma}$ (Gaussian noise)
4) Scale the plaintext: \(\Delta \cdot m\) → This embeds $m$ into the ciphertext space $\mathbb{Z}_q$
👉 Since $m \in [0, t)$ and $\Delta = \frac{q}{t}$,
\[\Delta m = \frac{q}{t} \cdot m \le \frac{q}{t}(t-1) = q - \frac{q}{t}\]→ Therefore, \(0 \le \Delta m < q\)
→ Thus, $\Delta m \in \mathbb{Z}_q$
5) Compute the ciphertext: \(b = A \cdot S + \Delta \cdot m + e \;\; \in \mathbb{Z}_q\)
2. Final Form
The LWE ciphertext is: \((A, b)\)
🔐 Summary B-2.2: LWE Encryption
1. Initial Setup
- $\Delta = \frac{q}{t}$, where $t$ divides $q$
- $S \in_R \mathbb{Z}_2^k$
2. Encryption Input
\[m \in \mathbb{Z}_t,\quad A \in_R \mathbb{Z}_q^k,\quad e \sim \chi_{\sigma}\]3. Encryption Steps
Scale the plaintext: \(\Delta \cdot m \in \mathbb{Z}_q\)
Compute: \(b = A \cdot S + \Delta \cdot m + e \pmod{q}\)
Output ciphertext: \(LWE_{S,\sigma}(\Delta m) = (A, b) \in \mathbb{Z}_q^{k+1}\)
B-2.3 Decryption
1. Decryption Steps
1) Given a ciphertext $(A, b)$, where
\[b = A \cdot S + \Delta \cdot m + e \;\; \in \mathbb{Z}_q\]2) Remove the secret-dependent term:
\[b - A \cdot S = \Delta \cdot m + e\]3) Recover the scaled message by rounding:
\[\left\lfloor \Delta \cdot m + e \right\rceil_{\Delta}\]→ Round to the nearest multiple of $\Delta$
👉 If $|e| < \frac{\Delta}{2}$, then: \(\left\lfloor \Delta m + e \right\rceil_{\Delta} = \Delta m\)
4) Recover the plaintext:
\[m = \frac{1}{\Delta} \cdot \left\lfloor \Delta m + e \right\rceil_{\Delta} = \frac{1}{\Delta} \cdot \Delta m = m\]🔐 Summary B-2.3: LWE Decryption
1. Decryption Input
\[C = (A, b) \in \mathbb{Z}_q^{k+1}\]2. Decryption Steps
Remove the secret term: \(b - A \cdot S = \Delta m + e \pmod{q}\)
Scale down: \(\frac{\left\lfloor \Delta m + e \right\rceil_{\Delta}}{\Delta} \;\; \bmod t = m \in \mathbb{Z}_t\)
3. Correctness Condition
\[e < \frac{\Delta}{2}\]→ Ensures correct rounding and successful decryption
2. Why Scaling by $\Delta$?
Scaling by $\Delta = \frac{q}{t}$ separates the plaintext and noise:
- Multiplying by $\Delta$ shifts $m$ to higher bits (by $\log_2 \Delta$ bits)
- The noise $e$ remains in the lower bits
During decryption, \(\frac{\Delta m + e}{\Delta} = m + \frac{e}{\Delta}\)
This effectively shifts the value back (right-shift), removing the noise through rounding.
👉 If $e$ is small, rounding recovers $m$ correctly.
B-2.3.1. In the Case of $t$ not Dividing $q$
1. Setting
Now suppose that $t$ does not divide $q$.
Then we set the scaling factor as:
\[\Delta = \left\lfloor \frac{q}{t} \right\rfloor\]→ Even if $m > t$, decryption still correctly recovers the result. But why?
2. Writing the plaintext as a wrapped value
To analyze this, we write the plaintext $m$ as
\[m = m' + kt, \quad m' \in \mathbb{Z}_t,\; k \in \mathbb{Z}\]Here, $m’$ is the actual value of $m$ modulo $t$, and $kt$ represents how many times $m$ has wrapped around modulo $t$.
So the goal of decryption is really to recover $m’ = m \bmod t$.
3. Expanding the scaled plaintext
The scaled plaintext with noise is
\[\left\lfloor \frac{q}{t} \right\rfloor m + e\]Substituting $m = m’ + kt$, we get
\[\left\lfloor \frac{q}{t} \right\rfloor m + e = \left\lfloor \frac{q}{t} \right\rfloor m' + \left\lfloor \frac{q}{t} \right\rfloor kt + e\]Now focus on the second term:
\[\left\lfloor \frac{q}{t} \right\rfloor kt\]Since
\[\frac{q}{t} = \left\lfloor \frac{q}{t} \right\rfloor + \left(\frac{q}{t} - \left\lfloor \frac{q}{t} \right\rfloor\right),\]we can rewrite it as
\[\left\lfloor \frac{q}{t} \right\rfloor kt = \frac{q}{t}kt - \left(\frac{q}{t} - \left\lfloor \frac{q}{t} \right\rfloor\right)kt\]Because
\[\frac{q}{t}kt = qk,\]this becomes
\[\left\lfloor \frac{q}{t} \right\rfloor kt = qk - \left(\frac{q}{t} - \left\lfloor \frac{q}{t} \right\rfloor\right)kt\]Therefore,
\[\left\lfloor \frac{q}{t} \right\rfloor m + e = \left\lfloor \frac{q}{t} \right\rfloor m' + qk - \left(\frac{q}{t} - \left\lfloor \frac{q}{t} \right\rfloor\right)kt + e\]4. What happens modulo $q$?
$qk$ is a multiple of $q$, so under modulo $q$ it disappears:
\[qk \equiv 0 \pmod q\]So after reduction modulo $q$, the expression behaves like
\[\left\lfloor \frac{q}{t} \right\rfloor m' - \left(\frac{q}{t} - \left\lfloor \frac{q}{t} \right\rfloor\right)kt + e\]That means the wrap-around part $kt$ does not remain as plaintext.
Instead, it gets absorbed into an additional error term.
5. Why is the extra error small?
Since
\[0 \le \frac{q}{t} - \left\lfloor \frac{q}{t} \right\rfloor < 1,\]we have
\[0 \le \left(\frac{q}{t} - \left\lfloor \frac{q}{t} \right\rfloor\right)kt < kt\]So this extra term is strictly smaller than $kt$.
The text therefore treats this part as an overestimated noise term and writes the expression conceptually as
\[\Delta m + e = \left\lfloor \frac{q}{t} \right\rfloor m + e \;\approx\; \left\lfloor \frac{q}{t} \right\rfloor m' + qk - e' + e,\]where $e’ = kt$ is used as an upper bound, since the extra term is strictly smaller than $kt$.
In other words, the wrap-around portion of $m$ does not destroy correctness.
It only contributes some bounded extra noise.
6. Decryption
Recall the LWE decryption relation:
\[b - A \cdot S \bmod q = \Delta m + e\]Using the rewritten form above,
\[\Delta m + e \;\approx\; \left\lfloor \frac{q}{t} \right\rfloor m' + qk - e' + e \pmod q\]Now divide by $\left\lfloor \frac{q}{t} \right\rfloor$ and reduce modulo $t$:
\[\left[ \frac{1}{\left\lfloor q/t \right\rfloor} \cdot \left( \left\lfloor \frac{q}{t} \right\rfloor m' + qk - e' + e \;\bmod q \right) \right] \bmod t\]7. Simplifying the expression
Since $qk \equiv 0 \pmod q$, the $qk$ term disappears:
\[\left[ \frac{1}{\left\lfloor q/t \right\rfloor} \cdot \left( \left\lfloor \frac{q}{t} \right\rfloor m' - e' + e \right) \right] \bmod t\]Now divide by $\left\lfloor q/t \right\rfloor$:
\[m' + \frac{-kt + e}{\left\lfloor q/t \right\rfloor} = m' - \frac{kt - e}{\left\lfloor q/t \right\rfloor} \pmod t\]→ For analysis, we upper bound this term as:
\[m' - \frac{kt + e}{\left\lfloor q/t \right\rfloor}\]since $kt + e$ is a safe upper bound on the total error.
8. Correctness condition
So decryption correctly recovers $m’$ as long as the total error is small enough:
\[\frac{kt + e}{\left\lfloor q/t \right\rfloor} < \frac{1}{2}\]If this holds, rounding removes the error term and we get
\[m' = m \bmod t\]9. Interpretation
This condition can fail if:
(1) $e$ is too large
The term $e$ is the intrinsic LWE noise.
If $e$ becomes large, then the total error
\[\frac{kt + e}{\left\lfloor q/t \right\rfloor}\]also increases.
→ The decrypted value may deviate too much, and rounding can fail.
(2) $t$ is too large
If $t$ increases, the scaling factor
\[\left\lfloor \frac{q}{t} \right\rfloor\]becomes smaller.
Since the error is divided by this value,
\[\frac{kt + e}{\left\lfloor q/t \right\rfloor}\]a smaller denominator leads to a larger overall error.
→ Intuitively, a larger $t$ weakens the scaling, so the noise is less suppressed.
(3) $k$ is too large
Recall:
\[m = m' + kt\]If $k$ is large, then the wrap-around term $kt$ also becomes large.
Although $kt$ does not remain as plaintext after modulo $q$,
it contributes to the total error.
→ More wrap-around ⇒ larger additional noise.
🔑 Key insight
To keep decryption correct, we want:
\[q \gg t\]so that
\[\left\lfloor \frac{q}{t} \right\rfloor\]is large enough to absorb both the intrinsic noise $e$ and the additional error from $kt$.
10. Final takeaway
Even when $t$ does not divide $q$, decryption still works by setting
\[\Delta = \left\lfloor \frac{q}{t} \right\rfloor\]The wrap-around part of $m$ does not remain in the plaintext.
It only contributes additional bounded noise.
So as long as
\[\frac{kt + e}{\left\lfloor q/t \right\rfloor} < \frac{1}{2},\]the decrypted result is still
\[m \bmod t\]