Codice PHP:
<?php
include("config.php");
function PasswordCasuale($lunghezza=100){
$caratteri_disponibili ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
$password = "";
for($i = 0; $i<$lunghezza; $i++){
$password = $password.substr($caratteri_disponibili,rand(0,strlen($caratteri_disponibili)-1),1);
}
return $password;
}
$stringa = addslashes($_POST['nota']);
$chiave = PasswordCasuale(500);
for ($i = 0; $i < strlen($stringa); $i++ ) {
$temp = $stringa[$i] ^ $chiave[$i % strlen($chiave)];
$crypt .= str_pad( dechex( ord( $temp ) ), 2, 0, STR_PAD_LEFT);
}
$val[0] = $chiave;
for($a = 1; $a<10; $a++){$stringa = $crypt;
$chiave = PasswordCasuale(500);
$crypt = "";
for ($i = 0; $i < strlen($stringa); $i++ ) {
$temp = $stringa[$i] ^ $chiave[$i % strlen($chiave)];
$crypt .= str_pad( dechex( ord( $temp ) ), 2, 0, STR_PAD_LEFT);
}
$val[$a] = $chiave;
}
$utente = $_SESSION["utente"];
$query = "INSERT INTO `notes` (
`username` ,
`nota` ,
`letto` ,
`1` ,
`2` ,
`3` ,
`4` ,
`5` ,
`6` ,
`7` ,
`8` ,
`9` ,
`10`
)
VALUES (
'$utente', '$crypt', '0', '$val[0]', '$val[1]', '$val[2]', '$val[3]', '$val[4]', '$val[5]', '$val[6]', '$val[7]', '$val[8]', '$val[9]'
)";
mysqli_query($connessione,$query);
?>