# C Code For Solving Modular Linear Equations

The Extended Euclid’s Algorithm solves the equation of the form

$GCD(a, n) = d = ax + ny$
If we multiply the both sides by (mod n), we get
$ax + ny \equiv d (\text{ mod } n)$
This is equivalent to,
$ax \equiv d (\text {mod } n)$
In this article, I present a C Programming Code to solve this type of modular linear equation.

### Congruence Modulo

You just saw a weird kind of mathematical expression of the form
$A \equiv B (\text { mod } C)$
This says that A is congruent to B modulo C. What does it mean? Before I tell you the meaning of above operator, please note that this kind of expression is every common in number theory. If you are interested in Cryptography and starting to learn it, you will encounter this operator numerous time. Lets take an example,
$21 \equiv 5 (\text { mod } 4)$
A symbol $equiv$ means “Equivalence”. In above equation, 21 and 5 are equivalent. This is because 21 modulo 4 = 1 is equal to 5 modulo 4 = 1. Another example is $51 \equiv 16 (\text{ mod } 7)$

The value of x can be more than one depending upon the GCD of a and n. There are always d number of solutions of x where d = GCD(a, n). If a and n are relatively prime i.e. GCD is 1, there is only one unique solution and this is very important for calculating secret key in RSA algorithm.

The following code solves the above relation. The code is also available on GitHub.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 2, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8512260317802429, "perplexity": 235.76525495682597}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-05/segments/1579250604397.40/warc/CC-MAIN-20200121132900-20200121161900-00350.warc.gz"}