"Implement a HTTP public-key repository for
key exchange that employs RSA-based digital
signatures."
I used Google App Engine Python for the web service, this is my app http://rsa-ds.appspot.com/.
The script to download and calculate the "r" and "y" is :
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
#!/usr/bin/python | |
def f(x): | |
return x*3*11*7 | |
def fastmodexp(x, y, mod): | |
p = 1 | |
aux = x | |
while y > 0: | |
if y % 2 == 1: | |
p = (p * aux) % mod | |
aux = (aux * aux) % mod | |
y = y >> 1 | |
return p | |
def main(): | |
x = int(raw_input("x: ")) | |
d = int(raw_input("d: ")) | |
n = int(raw_input("n: ")) | |
y = f(x) | |
r = fastmodexp(y, d, n) | |
print "La r es = " + str(r) | |
main() |
Google app python:
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
import cgi | |
import webapp2 | |
import random | |
from google.appengine.api import users | |
import datetime | |
from google.appengine.ext import db | |
def f(x): | |
"""devuelve un valor de y | |
""" | |
return x*3*11*7 | |
def fastmodexp(x, y, mod): | |
p = 1 | |
aux = x | |
while y > 0: | |
if y % 2 == 1: | |
p = (p * aux) % mod | |
aux = (aux * aux) % mod | |
y = y >> 1 | |
return p | |
class Usuario(db.Model): | |
nombre = db.StringProperty(required=True) | |
e = db.StringProperty(required=True) | |
n = db.StringProperty(required=True) | |
######## users test######## | |
a = Usuario(nombre="cecy", | |
e="59", | |
n="5767") | |
a.put() | |
b = Usuario(nombre="daniel", | |
e="13", | |
n="2773") | |
b.put() | |
c = Usuario(nombre="pedro", | |
e="23", | |
n="3293") | |
c.put() | |
d = Usuario(nombre="lupita", | |
e="89", | |
n="3649") | |
d.put() | |
############################ | |
class MainPage(webapp2.RequestHandler): | |
"""clase principal que muestra el formulario | |
""" | |
def get(self): | |
x = int(random.random()*100) | |
self.response.out.write(""" | |
<html> | |
<head> <link type="text/css" rel="stylesheet" href="/bootstrap/css/bootstrap.css" /> | |
</head> | |
<body> | |
<div class="container"> | |
<form class="form-horizontal" action="/generate" method="post"> | |
<legend>RSA-based digital signatures</legend> | |
<div class="control-group"> | |
<label class="control-label">Challenge</label> | |
<div class = "controls"> | |
<input type="text" name="x" value="%s" readonly="readonly"/> | |
<a class="btn" href="http://rsa-ds.appspot.com/"><i class="icon-cog"></i>Generate</a> | |
</div></div> | |
""" %x) | |
usuarios = db.GqlQuery("SELECT * FROM Usuario") | |
self.response.out.write("""<div class="control-group"> | |
<label class="control-label"><i class="icon-user"></i> | |
User</label> | |
<div class="controls"> | |
<select name="usuario">""") | |
for i in usuarios: | |
self.response.out.write("""<option>""") | |
self.response.out.write("""%s""" %i.nombre) | |
self.response.out.write("""</option>""") | |
self.response.out.write("""</select> | |
<a class="btn" href="https://docs.google.com/open?id=0BzBiYAUF68vdNFEzMnFIaWhrcjQ"> | |
<i class="icon-download-alt"></i>Download script</a></div></div> | |
<div class="control-group"> | |
<label class="control-label"><i class="icon-edit"></i>r</label> | |
<div class="controls"> | |
<input class="input-large" type="text" name="r" placeholder="numeric value" size="10" /></div></div> | |
<div class="controls"> | |
<button type="submit" class="btn btn-primary"><i class="icon-check icon-white"></i> Validate</button></div> | |
</form>""") | |
self.response.out.write("""</div></body> | |
</html>""") | |
class Calculo(webapp2.RequestHandler): | |
def post(self): | |
self.response.out.write("""<html><head> | |
<link type="text/css" rel="stylesheet" href="/bootstrap/css/bootstrap.css" /></head> | |
<body><div class="container">""") | |
usuario = self.request.get('usuario') | |
r = self.request.get('r') | |
x = self.request.get('x') | |
y = f(int(x)) | |
us = db.GqlQuery("""SELECT * FROM Usuario WHERE nombre = '%s'""" %usuario) | |
for i in us: | |
e = i.e | |
n = i.n | |
nombre = i.nombre | |
try: | |
y1 = fastmodexp(int(r), int(e), int(n)) | |
self.response.out.write("""<div class="row">User: %s</div> | |
<div class="row">r: %s</div> | |
<div class="row">x: %s</div>""" %(usuario, r, x)) | |
self.response.out.write("""<div class="row">y = f(x) = %s</div>""" %y) | |
self.response.out.write("""<div class="row">Public key: (e,n) = | |
(%s, %s)</div>""" %(e, n)) | |
self.response.out.write("""<div class="row">y1 = r^e mod n = %s</div>""" %y1) | |
if y1 == y: | |
self.response.out.write('<div class="row"><p class="text-success">Yes, it is correct</p></div>') | |
else: | |
self.response.out.write('<div class="row"><p class="text-error">Is incorrect</p></div>') | |
except ValueError: | |
self.response.out.write('<div class="row">r must be a numeric value</div>') | |
self.response.out.write('<div class="row"><a href="http://rsa-ds.appspot.com/">Retry</a></div>') | |
self.response.out.write('</div></body></html>') | |
app = webapp2.WSGIApplication([('/', MainPage), | |
('/generate', Calculo)], | |
debug=True) |
Database:
Screenshots:
Script:
App:
Result:
Script:
App:
Result:
App:
Result:
App:
Result: