Skip to content

Instantly share code, notes, and snippets.

@soul0592
Created July 3, 2013 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soul0592/5916327 to your computer and use it in GitHub Desktop.
Save soul0592/5916327 to your computer and use it in GitHub Desktop.
Servidor rsa
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