Here the code:
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
<html> | |
<head> | |
<h1>Web Service -RSA-</h1> | |
</head> | |
<body> | |
<form action="/index.php" method="post"> | |
<table> | |
<tbody> | |
<tr> | |
<td>Challenge: | |
<?php | |
$x = rand(1,100); | |
echo "<input type='text' placeholder='$x' size='11'/>"; | |
echo "<input type='hidden' name='challenge' value='$x'>";?> | |
<input type="submit" name="Generate" value="Generate" /></td> | |
</tr> | |
</form> | |
<tr> | |
<td><a href= script.py target=_balnk><button>Download script</button></a></td></tr> | |
<tr> | |
<td><form action="prove.php" method="post"> | |
User:<input type="text" name="User" required size="20" value="" /><tr/> | |
<input type='hidden' name='x' value= "<?php echo $x; ?>" > | |
<tr><td>r: <input type="text" name="R" required placeholder="response" size="20" value=""/></td></tr> | |
<tr><td><input type="submit" name="validate" value="Validate"></td> | |
</form> | |
</tr> | |
</form> | |
</table> | |
</body> | |
</html> |
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
<html> | |
<body> | |
<?php | |
$user = $_REQUEST['User']; | |
$lines=file('base.txt'); | |
$i=0; | |
$r = $_REQUEST['R']; | |
$x = $_REQUEST['x']; | |
echo "Valor de x $x"; | |
echo "valor de r $r"; | |
while($lines[$i]!=NULL){ | |
$row = $lines[$i+1]; | |
$sql = explode(",",$row); | |
$i++; | |
$aux = $sql[0]; | |
if (strcmp($user,$aux) ==0 ){ | |
$y = $x * 3 + 5; | |
$n = $sql[1]; | |
$e = $sql[2]; | |
} | |
else | |
{ | |
//echo "si pasa aka"; | |
// "<br/ >"; | |
} | |
} | |
?> | |
<?php | |
$k = 1; | |
$u = $r % $n; | |
while (e >0) | |
{ | |
if(($e % 2) == 1) | |
{ | |
$k = ($k*$u) % $n; | |
} | |
$e = $e/2; | |
$u=($u*$u) % n; | |
} | |
$y = $x * 3+5; | |
echo "imprimo $k"; | |
echo "imprimo $y"; | |
if ($k == $y){ | |
echo "is him! :)"; | |
}else | |
{ | |
echo "not him :C"; | |
} | |
?> | |
</body> | |
</html> |
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+5 | |
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("write your x: ")) | |
d = int(raw_input("write your d: ")) | |
n = int(raw_input("write your n: ")) | |
y = f(x) | |
r = fastmodexp(y, d, n) | |
print "your r is = " + str(r) | |
print "Give your r to your friend :)" |
here some images
http://alejandroave.260mb.org/Obed/
This fails when n is smaller than the challenge or when the key is large. We're also missing the second example (I was expecting to see a success and a failure). 7 pts.
ResponderEliminar