Diferencia entre revisiones de «Implementación de algoritmos de teoría de números/Exponenciación modular»

Contenido eliminado Contenido añadido
Raulshc (discusión | contribs.)
Raulshc (discusión | contribs.)
+cambio de tag
 
Línea 60:
 
==== Algoritmo de derecha a izquierda ====
<sourcesyntaxhighlight lang="c">
long powmod(long a, long e, long n){
long accum = 1, apow, x;
Línea 71:
return accum;
}
</syntaxhighlight>
</source>
 
==== Algoritmo de derecha a izquierda con GMP ====
Línea 77:
La biblioteca GMP tiene una función <code>mpz_powm(result,a,e,n)</code>, así que no es necesaria esta implementación, pero se muestra aquí como método explicativo.
 
<sourcesyntaxhighlight lang="c">
// High to Low powmod algorithm
int powmod(mpz_t result, mpz_t a, mpz_t e, mpz_t n) {
Línea 99:
return 1;
}
</syntaxhighlight>
</source>
 
=== Java ===
 
==== Algoritmo de derecha a izquierda ====
<sourcesyntaxhighlight lang="java">
public static long powmod(long a, long e, long n){
long accum = 1;
Línea 118:
return accum;
}
</syntaxhighlight>
</source>
 
==== Algoritmo de derecha a izquierda con BigInteger ====
Línea 124:
La clase BigInteger de Java tiene un método <code>modPow(e, n)</code>, así que no es necesaria esta implementación, pero se muestra aquí como método explicativo.
 
<sourcesyntaxhighlight lang="java">
// High to low powmod algorithm
public static BigInteger POWMOD(BigInteger a, BigInteger e, BigInteger n) {
Línea 138:
return accum;
}
</syntaxhighlight>
</source>
 
=== Python ===
Línea 145:
 
Python tiene una función <code>pow(a, e, n)</code>, así que no es necesaria esta implementación, pero se muestra aquí como método explicativo.
<sourcesyntaxhighlight lang="python">
def powmod(a,e,n):
accum = 1; i = 0; apow2 = a
Línea 154:
i += 1
return accum
</syntaxhighlight>
</source>
 
== Referencias ==