Created
July 3, 2013 08:22
-
-
Save soul0592/5916327 to your computer and use it in GitHub Desktop.
Servidor rsa
This file contains 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 rsa import public,e,d,cifrar,decifrar | |
from random import randint | |
from sys import argv | |
import socket | |
def main(): | |
socket1 = socket.socket() | |
print "Servidor iniciando..." | |
socket1.bind(("localhost", 9999)) | |
socket1.listen(1) | |
(publica,privada) = public(int(argv[1])) | |
(socket2, address) = socket1.accept() | |
print "Iniciado. Conectando..." | |
conexion = randint(1,100) | |
socket2.send(str(conexion)) | |
resp = socket2.recv(512) | |
resp_conexion = d(int(resp), publica) | |
if conexion == resp_conexion: | |
socket2.send("Conectado") | |
print "Conectado. Esperando mensaje..." | |
mensaje = socket2.recv(512) | |
num = int(mensaje) | |
plaintxt = decifrar(d(num,privada)) | |
print 'Mensaje recibido: ',plaintxt | |
else: | |
print "Error de conexion." | |
print "Conexion terminada." | |
socket2.close() | |
socket1.close() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment