jueves, 20 de septiembre de 2012

week number 6




In this week, we need to aplicated a serves web with rsa system


Some introdcuccin

In the web serves some peple for example alice generetd "X" and seend this a Bob.
Bob will dowload some script to put him privated keys and the x, before bob sends result "r", and alice put the result in the serves and user, finaly the serves says if bob is bob or not


Code1 :
<html>
<head>
<title>Sistem of autentification</title>
</head>
<body>
<H1>Download script python</H1>
<a href= script.py target=_blank><button>clic here</button></a>
<?php
//generet random "x"
$num=rand(1,50);
$variable=rand(1,50);
?>
<p>
<?php
//Send with method reference the value of x
?>
<H1>Challenge:</H1>
<a href="accion.php?var=<?php echo $variable; ?>"/>
<p><input type="submit" VALUE="send"/></p>
</p>
</body>
view raw index.php hosted with ❤ by GitHub


Code2:
Value of x:
<?php
//obtain value of x and
// show value of x
$num = $_GET["var"];
echo $num;
?>
<?php
//send values of user, r and value of x for future algoritms
?>
<H1>Verification:</H1>
<FORM ACTION="verificar.php" METHOD="GET">
Value of r: <INPUT TYPE="text" NAME="r"><BR>
User name: <INPUT TYPE="text" NAME="usuario"><BR>
<input type="hidden" name="x" value="<?php echo $num; ?>">
<INPUT TYPE="submit" VALUE="Enviar">
</FORM>
view raw accion.php hosted with ❤ by GitHub

Code3:
<html>
<head>
<title>Verification</title>
</head>
<body>
value of y =
<?php
//Calculated value of y
$a = 3;
$num = $_GET['x'];
$numy = $num + $a;
echo $numy;
?>
<H1>Verification</H1>
The name you entered is : <?php echo $_GET['usuario'] ?>
R: <?php echo $_GET['r'] ?>
Valor de x: <?php echo $_GET['x'] ?>
<br>
<?php
//read some file.dat to found user and the keys
$filas=file('user.dat');
// array about the values
$campos = array('id', 'e', 'n');
$c = 0;
$cadena = $_GET['usuario'];
$lugar = 0;
$e = 0;
$n = 0;
//iterator about array in this case the line of file
foreach($filas as $v){
//save array after for some separation o caracter in this case ","
$datos=explode(",",$v);
//iterate arrays about the line with the separation
foreach($datos as $dato){
//comparate the user(cadena) vs line
if(strcmp($dato, $cadena) != 0) {
//echo "User was not found";
}
else
{
echo "User was found";
//if found save the information in some variable
$e = $datos[1];
$n = $datos[2];
}
$c++;
}
$c = 0;
echo "<p />";
}
?>
<?php
//process about the verification
$r = $_GET['r'];
//algoritmy to calculated the module
$lle = 1;
$u = $r % $n;
while ($e > 0)
{
if(($e % 2) == 1)
{
$lle = ($lle*$u) % $n;
}
$e = $e/2;
$u = ($u*$u) % $n;
}
//algoritmy to calculated the module
if ($numy == $lle)
{
echo "its really him/her";
}
else
{
echo " is not him/her";
}
?>
</body>
</html>


Script of dowload:

y = 0
r = 0
d = 0
x = 0
##funcion of f(x)
def funcionx(x):
global y
y = x + 3
##funcion to obtain r with Modular exponentiation algorithm i used this method to
##calculated r and desencript messenge in the php. Reference link about the
##algoritm: http://web.usal.es/~hernando/segi2012/11HerrMat.pdf
def funcionr():
global r,d,n,y
lle = 1
u = y % n
while (d > 0):
if((d % 2) == 1):
lle = (lle*u) % n
d = d/2
u = (u*u) % n
r = lle
def main():
global d,n
print "Dar valores de tu clave privada: "
x = int(raw_input("Dame el valor de x: "))
d = int(raw_input("Dame el valor de d: "))
n = int(raw_input("Dame el valor de n: "))
funcionx(x)
funcionr()
print "Valor de y = ",y
print "Valor de r:",r
main()
view raw script.py hosted with ❤ by GitHub
Screen4:


 Ramón used my server some pictures:




and triana (in this case was not yet translated)



Link of servece: http://alejandroave.260mb.org/
Apologies for publicity :C but "ITS FREE"

Reference:
http://php.net/manual/es/control-structures.foreach.php
http://php.net/manual/es/function.explode.php
http://php.net/manual/es/tutorial.php
http://web.usal.es/~hernando/segi2012/11HerrMat.pdf

1 comentario:

  1. -1 por ortografía, -1 por limitación de tamaño de clave por PHP; 8 pts.

    ResponderEliminar