0% found this document useful (0 votes)
26 views

Modification of Euclidian Algorithm

The document proposes a modification of the extended Euclidean algorithm to more efficiently solve modular equations and systems of modular equations. The modification uses residue or residue complement values where appropriate to reduce the number of iteration steps. For an example equation 233x ≡ 7 (mod 144), the standard algorithm requires 12 steps while the modified algorithm only requires 7 steps. The modified algorithm can also be used to solve systems of modular equations based on the Chinese Remainder Theorem and is amenable to parallel implementation.

Uploaded by

ie2007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Modification of Euclidian Algorithm

The document proposes a modification of the extended Euclidean algorithm to more efficiently solve modular equations and systems of modular equations. The modification uses residue or residue complement values where appropriate to reduce the number of iteration steps. For an example equation 233x ≡ 7 (mod 144), the standard algorithm requires 12 steps while the modified algorithm only requires 7 steps. The modified algorithm can also be used to solve systems of modular equations based on the Chinese Remainder Theorem and is amenable to parallel implementation.

Uploaded by

ie2007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SCIENTIFIC PUBLICATIONS OF THE STATE UNIVERSITY OF NOVI PAZAR

SER. A: APPL. MATH. INFORM. AND MECH. vol. 4, 2 (2012), 41-44.


Modication of Euclidian Algorithm for Solving Modular
Equations
I.

Z. Milovanovi c,

C. B. Doli canin, M. K. Stoj cev, E. I. Milovanovi c
Abstract: In this paper we propose a modication of extended Euclids algorithms with aim to
reduce the number of iteration steps when solving modular equations. Obtained result is used
to solve the system of linear modular equations in one variable (Chinese Remainder Theorem).
The proposed modication is convenient for parallel implementation.
Keywords: Euclidian algorithm, residue, Chinese reminder theorem.
1 Introduction
The Euclidean algorithm(also called Euclids algorithm) is an efcient method for com-
puting the greatest common divisor (GCD) of two integers a and b. It is one of the oldest
numerical algorithms still in common use [1, 2]. The algorithm has many theoretical and
practical applications. It is a key element of the RSA algorithm, a public-key encryption
method widely used in electronic commerce. It is used to solve Diophantine equations,
such as nding numbers that satisfy multiple congruences (Chinese remainder theorem) or
multiplicative inverses of a nite eld. It can also be used to construct continued fractions,
in the Sturm chain method for nding real roots of a polynomial, and in several modern
integer factorization algorithms. Finally, it is a basic tool for proving theorems in modern
number theory, such as Lagranges four-square theorem and the fundamental theorem of
arithmetic (unique factorization) [3, 4].
In this paper we propose one modication of extended Euclidian algorithm for solving
modular equations and system of modular equations. The modication is based on the
usage of residue or residue complement, where appropriate, which can reduce the number
of iteration steps substantially.
Manuscript received March 17, 2012; accepted May 25,2012.
I.

Z. Milovanovi c, M. K. Stoj cev and E. I. Milovanovi c are with the Faculty of Electronic Engineering,
University of Ni s, Ni s, Serbia;

C. B. Doli canin is with the State University of Novi Pazar, Novi Pazar, Serbia.
41
42 I.

Z. Milovanovi c,

C. B. Doli canin, M. K. Stoj cev, E. I. Milovanovi c
2 Solving of modular equations
Let us consider a modular equation in one variable
ax c( modb) (1)
where a, b and c are integers so that GCD(a, b) divides c, denoted as GCD(a, b)|c. Suppose
X
0
is an arbitrary particular solution of equation(1). Then general solution is of the form
x =
C
GCD(a, b)
X
0
+
b t
GCD(a, b)
, t Z.
This means that to solve the equation (1) it is necessary to know X
0
and GCD(a, b). These
are usually determined by the extended Euclidian algorithm (see [2, 3, 5, 6]).
Algorithm 1 (Extended Euclidian)
r1 := a; ; r2 := b;
x1 := 1; x2; = 0;
}
initialization
while (r = 0) do
{
q :=
r
1
r
2
;
r := r1qr2;
r1 := r2; r2 := r;
x := x1qx2;
x1 := x2; x2 := x;
}
GCD := r1; X
0
:= x1;
In order to reduce the number of iteration steps, we propose the following modication
of Algorithm 1
Algorithm 2 (Modied extended Euclidian)
r1 := a; ; r2 := b;
x1 := 1; x2; = 0;
rr := a mod b; rs := brr;
/* rr is residuo; rs is residuo complement */

initialization
while (rr rs = 0) do
if (rr < rs) then
{ q :=
r
1
r
2
;
rr := r1qr2;
r1 := r2; r2 := rr;
Modication of Euclidian Algorithm for Solving Modular Equations 43
x := x1qx2;
x1 := x2; x2 := x; }
else
{ q :=
r
1
r
2
;
rs := r1qr2;
r1 := r2; r2 := rs;
x := qx2x1;
x1 := x2; x2 := x; }
GCD := r1; X0 := x1;
For the sake of illustration of running Algorithm 1 and 2, we will take the following
equation
233x 7( mod144) (2)
Table 1 outlines execution steps when Algorithm 1 and Algorithm 2 are used.
Table 1.
Algorithm 1 Algorithm 2
step q r
1
r
2
r x
1
x
2
x q r
1
r
2
r x
1
x
2
x
1 1 233 144 89 1 0 1 2 233 144 55 1 0 -1
2 1 144 89 55 0 1 -1 3 144 55 21 0 -1 -3
3 1 89 55 34 1 -1 2 3 55 21 8 -1 -3 -8
4 1 55 34 21 -1 2 -3 3 21 8 3 -3 -8 -21
5 1 34 21 13 2 -3 5 3 8 3 1 -8 -21 -55
6 1 21 13 8 -3 5 -8 3 3 1 0 -21 -55 -309
7 1 13 8 5 5 -8 13 1 -55 89
8 1 8 5 3 -8 13 -21 GDC(233, 144) = 1 X
0
= 55
9 1 5 3 2 13 -21 34
10 1 3 2 1 -21 34 -55
11 2 2 1 0 34 -55 149
12 1 0 -55 89
GDC(233, 144) = 1 X
0
= 55
As can be seen from Table 1, Algorithm 1 requires 12 computational steps, while
Algorithm 2 requires 7 steps. Algorithm 2 uses one additional testing at the beginning of
the loop. All other computational steps in the loop body of both algorithms are of identical
complexity. This obviously justies the usage of the involved modication.
In the sequel we will show how Algorithm 2 can be used for solving the system of
modular equations in one variable based on Chinese remainder theorem.
Consider the following system of modular equations
x c
1
( modb
1
)
x c
2
( modb
2
) (3)
44 I.

Z. Milovanovi c,

C. B. Doli canin, M. K. Stoj cev, E. I. Milovanovi c
.
.
.
x c
k
( modb
k
)
where b
i
and c
i
are integers, and b
i
, i =1, 2, . . . , n are pairwise relatively prime. If we denote
by x
j
, j = 1, 2, . . . , n, solutions of the corresponding modular equations in system (3), i.e.
a
j
x
j
c
j
( modb
j
), a
j
=
b
1
b
2
. . . b
k
b
j
=
b
b
j
, (4)
then a particular solution of system (3) is given by
x
(
k

j=1
a
j
x
j
)
mod b. (5)
If minimal positive solution of system (3) is required, then in (5) instead of mod a
function Mod dened in [7] should be used.
Finally, let us note that computations dened by (4) have high degree of data parallelism
and can be performed in parallel since the computations of x
j
, j =1, 2, . . . , n are completely
independent from each other (see for example [8, 9].
References
[1] J. M. ANDERSON, Discrete mathematics with combinatorics, Prentice Hall, New Jersey,
2004.
[2] D. KNUTH, The art of computer programming, Vol. 2, Semi-numerical algorithms, Reading
MA: Addison-Wesley, 1981.
[3] A. G. AKRITAS, Elements of computer algebra with applications, John Wiley and Sons,
Inc., New York, 1989.
[4] S. M. KUO, B. H. LEE, W. TIAN, Real-time digital signal processing: Implementations
and applications, John Wiley and Sons, Inc. 2006.
[5] R. P. BRENT, H. T. KUNG, Systolic VLSI arrays for polynomial GCD computation, Report
CMU-CS-82-118, Carnegie-Mellon University, 1982.
[6] R. P. BRENT, H. T. KUNG, F. T. LUK, Some linear-time algorithms for systolic arrays,
arXiv: 1004.3716V1,[CS.DS], 21. Apr. 2010.
[7] M. K. STOJ CEV, E. I. MILOVANOVI C, I.

Z. MILOVANOVI C, A unied approach in ma-
nipulation with modular arithmetic, Proc.: 28 International Conference on Microelectronics,
(MIEL12), Ni s, Serbia, 2012, 387-392.
[8] S. G. AKL, The design and analysis of parallel algorithms, Prentice-Hall Inc. 1989.
[9] A. BORODIN, J. GATHEN, J. HOPCROFT, Fast parallel matrix and GCD computations,
Proc. : 23rd Annual Symposium on Foundations of Computer Science, IEEE, New York,
1982, 65-71.

You might also like