This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function encrip($mensaje, $clave, $n){ | |
| return expmod($mensaje, $clave, $n); | |
| } | |
| function expmod($a, $b, $n){ | |
| $rexpo = 1; | |
| $pot = $a % $n; | |
| while ($b > 0) { | |
| if ($b % 2 == 1){ | |
| $rexpo = ($rexpo * $pot) % $n; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def generarprimo(): | |
| minimo = 20 | |
| while True: | |
| p = random.randrange(2, 9999999) | |
| if miller(p): | |
| auxiliar = (p - 1) / 2 | |
| if miller(auxiliar): | |
| a = factorizar(p - 1) | |
| lga = a[len(a) - 1] | |
| b = factorizar(p + 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function RSA(){ | |
| var e_generado = document.getElementById('e'); | |
| var d_generado = document.getElementById('d'); | |
| var n_generado = document.getElementById('n'); | |
| var p = generarPrimo(); | |
| var q = generarPrimo(); | |
| while (p === q){ | |
| } | |
| var n = p * q; | |
| var fn = (p-1)*(q-1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from miller import miller | |
| from factorizar import factorizar | |
| from gcd import gcd, egcd | |
| import random | |
| class RSA: | |
| def __init__(self): | |
| self.generarN() | |
| self.generarE() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Hacker(Persona): | |
| def __init__(self, p, g, name): | |
| self.name = name | |
| self.p = p | |
| self.g = g | |
| self.llave_privada = 0 | |
| self.eval = 0 | |
| self.llave_compartida = 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mint@mint ~/Desktop/diffie_protocol $ python diffie.py 199 | |
| p, g | |
| 199 95 | |
| Alice: llave privada 42 - evaluacion 52 - llave compartida 61 | |
| Bob: llave privada 171 - evaluacion 96 - llave compartida 61 | |
| empieza el hackeo | |
| 1 95 | |
| 2 70 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Persona: | |
| def __init__(self, p, g, name): | |
| self.name = name | |
| self.p = p | |
| self.g = g | |
| self.llave_privada = random.randrange(1, p) | |
| self.eval = 0 | |
| self.llave_compartida = 0 | |
| self.evaluarLlave() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from factorizar import factorizar, divisores | |
| # divisores y factorizar -> se ocupan para verificar que un numero es generador de otro | |
| def generador(p): | |
| generadores = [] | |
| factores = factorizar(p - 1) | |
| divisor = divisores(factores) | |
| for i in xrange(2, p - 1): | |
| esgenerador = validargenerador(i, divisor, p) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Diffie: | |
| def __init__(self, p): | |
| self.p = p | |
| self.g = 0 | |
| self.generadores() | |
| print 'p, g' | |
| print self.p, self.g | |
| self.Alice = Persona(self.p, self.g, "Alice") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| En la descripción original del problema de la clase | |
| se pidió encontrar un X tal que satisfaga las siguientes congruencias. | |
| 4 congruencia X mod 2 | |
| 5 congruencia X mod 3 | |
| 6 congruencia X mod 5 | |
| 7 congruencia X mod 7 | |
| 8 congruencia X mod 11 | |
| 9 congruencia X mod 13 |