<?php
require("conn.php");
?>
<html>
<head>
<script>
function generar(inf,sup){
numP = sup - inf;
rnd = Math.random() * numP;
rnd = Math.round(rnd);
document.formulario.challengen.value=parseInt(inf) + rnd;
}
</script>
</head>
<a href="script.py">Descargar script</a>
<form name="formulario" method="POST" action="validar.php" >
<b>Challenge:</b><input type="text" name="challengen"><input type="button" value="Generate" onclick="generar(0,100)">
<br><b>User:</b><select name="user">
<?php
$query="SELECT user FROM users";
$result=mysql_query($query,$conn);
while($row=mysql_fetch_array($result)){
echo "<option value=\'".$row["user"]."\'>".$row["user"]."</option>";
}
?>
</select>
<br><b>Response:</b><input type="text" name="response">
<br><input type="submit" value="submit">
<?php
function f($x){
return ($x*10+3);
}
function 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);
}
if(isset($_POST[\'response\']) and isset($_POST[\'user\']) and isset($_POST[\'challengen\'])){
$usuario = $_POST[\'user\'];
$x = $_POST[\'challengen\'];
$r = $_POST[\'response\'];
$query="SELECT E,N From users WHERE user = \'". $usuario."\'";
$result=mysql_query($query,$conn);
$publica = mysql_fetch_array($result);
$e = $publica["E"];
$n = $publica["N"];
$y = f($x);
$num = fastmodexp($r, $e, $n);
if ($y == $num){
echo "<strong><h2>Yes, it was ". $usuario ." :)</h2></strong>";
} else {
echo "<strong><h2>No, it wasn\'t ". $usuario ." :(</h2></strong>";
}
} ?>
</form>
</html>
--------------------------------------SCRIPT---------------------------------------------
def f(x):
return x*x+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()
----------------------------------------------------------------------------