Chinese Remainder Theorem


Instructions: Enter a number in the box labeled x:. Enter relatively prime numbers in boxes labeled n1: up to n5:. It is OK to leave one or more of these boxes blank. Click on Encrypt and n mod xi will appear in box labeled x%ni for each i where box ni: was not blank. The product of all non-blank ni: boxes appears in the box labeled prod:. Click on Decrypt to compute x from the information in the x%ni: and ni: boxes. Each box labeled ~ni: will contain the number in box prod: divided by the number in ni:. Each box labeled si: will contain the inverse of the number in box ~ni: mod the number in prod:. The green box will contain the sum, mod prod:, of the products of the three numbers in each of the non-blank columns between the two buttons. If x is less than prod and all ni are relatively prime, then the green box should contain the same number as the upper left box labeled x:.


  1. If x is greater than prod the wrong answer is obtained - that is, decryption fails to reconstruct x.
  2. If all the ni are not relatively prime, the wrong answer is obtained.

Source code: