LogoLogo
LogoLogo
  • Introduction
    • About Us
    • Notations & Definitions
      • MPC
      • ZK
    • Contribute to this Site!
  • Primitives
    • Multiplication
      • Karatsuba Multiplication
      • Toom-Cook Multiplication
    • NAF (Non-adjacent form)
    • Chinese Remainder Theorem (CRT)
    • Euclidean Algorithm
      • Extended Euclidean Algorithm
      • Binary Euclidean Algorithm
      • Extended Binary Euclidean Algorithm
    • Coding Theory
      • Linear Code
    • Number Theoretic Transform
    • Abstract Algebra
      • Group
        • -Morphisms
        • Batch Inverse
      • Elliptic Curve
        • Weierstrass Curve
          • Coordinate Forms
          • Fast Elliptic Curve Arithmetic and Improved WEIL Pairing Evaluation
        • Edwards Curve
          • Coordinate Forms
          • Twisted Edwards ↔ Short Weierstrass Transformation
        • Batch Inverse for Batch Point Additions
        • Scalar Multiplication
          • Double-and-add
          • GLV Decomposition
        • MSM
          • Pippenger's Algorithm
          • Signed Bucket Index
          • CycloneMSM
          • EdMSM
          • cuZK
        • 2-Chain and 2-Cycle of Elliptic Curves
    • Encryption Scheme
      • ElGamal Encryption
    • Modular Arithmetic
      • Modular Reduction
        • Barrett Reduction
        • Montgomery Reduction
      • Modular Inverse
        • Bernstein-Yang's Inverse
    • Multiset Check
    • Sumcheck
    • Commitment Scheme
      • Fflonk
      • SHPlonk
      • Zeromorph
  • MPC
    • Yao's Garbled Circuits
    • GMW
    • BMR
  • ZK
    • Arithmetization
      • R1CS
      • PLONK
      • AIR
    • Folding
      • LatticeFold
      • Nova
        • Nova over Cycles of Curves
    • Lookup
      • Lasso
      • LogUp-GKR
    • SNARK
      • Groth16
      • HyperPlonk
      • Spartan
        • SPARK
    • STARK
      • Additive NTT
      • Basefold
      • Binius
      • Brakedown
      • CircleSTARK
      • FRI
        • FRI Security Features and Optimizations
      • DEEP FRI
      • STIR
      • WHIR
    • Distributed ZK
      • Ryan's Trick for Distributed Groth16
  • Application
    • zkLogin
    • zkHoldem
    • zkTLS
      • DECO
      • Proxying is enough
  • zkVM
Powered by GitBook
On this page
Export as PDF
  1. Primitives

Chinese Remainder Theorem (CRT)

PreviousNAF (Non-adjacent form)NextEuclidean Algorithm

Last updated 1 month ago

Given N=∏i=1kniN = \prod_{i=1}^{k}n_iN=∏i=1k​ni​ where each moduli(or divisor) nin_ini​ is a pairwise , and the set of aia_iai​ is given as below:

x≡a1(modn1)⋮x≡ak(modnk)x \equiv a_1 \pmod {n_1} \\ \vdots \\ x \equiv a_k \pmod {n_k}x≡a1​(modn1​)⋮x≡ak​(modnk​)

Then the system has a unique solution xxx under modulo NNN such that:

x≡s1⋅∏i≠1ni+s2⋅∏i≠2ni+⋯+sk⋅∏i≠kni(modN)x \equiv s_1 \cdot \prod_{i \ne 1} n_i + s_2 \cdot \prod_{i \ne 2} n_i + \cdots + s_k \cdot \prod_{i \ne k} n_i \pmod Nx≡s1​⋅i=1∏​ni​+s2​⋅i=2∏​ni​+⋯+sk​⋅i=k∏​ni​(modN)

where each sis_isi​ satisfies:

si⋅∏j≠inj=ai(modni)s_i \cdot \prod_{j \ne i} n_j = a_i \pmod {n_i}si​⋅j=i∏​nj​=ai​(modni​)

In other words, a set of modulus statements can be reduced to a single statement.

Take the example below:

x={2(mod3)3(mod5)2(mod7)x = \begin{cases} 2 \pmod 3 \\ 3 \pmod 5 \\ 2 \pmod 7 \end{cases}x=⎩⎨⎧​2(mod3)3(mod5)2(mod7)​
35⋅s1≡2⋅s1≡2(mod3)21⋅s2≡s2≡3(mod5)15⋅s3≡s3≡2(mod7)35 \cdot s_1 \equiv 2 \cdot s_1 \equiv 2 \pmod 3 \\ 21 \cdot s_2 \equiv s_2 \equiv 3 \pmod 5 \\ 15 \cdot s_3 \equiv s_3 \equiv 2 \pmod 7 \\35⋅s1​≡2⋅s1​≡2(mod3)21⋅s2​≡s2​≡3(mod5)15⋅s3​≡s3​≡2(mod7)

Solving these gives s1=1,s2=3s_1 = 1, s_2 = 3s1​=1,s2​=3 and s3=2s_3 = 2s3​=2. Then the solution is

x≡1⋅35+3⋅21+2⋅15≡128≡23(mod105)x \equiv 1 \cdot 35 + 3 \cdot 21 + 2 \cdot 15 \equiv 128 \equiv 23 \pmod {105}x≡1⋅35+3⋅21+2⋅15≡128≡23(mod105)

Written by from

coprime
A41
ryan Kim