Con il seguente codice
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_paddechexord$temp ) ), 20STR_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_paddechexord$temp ) ), 20STR_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); 
?>
Dovrei crittare una stringa, inviata tramite form, per dieci volte, con dieci chiavi diverse generate in modo casuale.
Sembra funzionare tutto alla meraviglia. Il problema si pone quando devo tornare alla stringa di partenza.
Ho provato ad utilizzare questo codice:
Codice PHP:
$note mysqli_fetch_assoc(mysqli_query($connessione,"SELECT * FROM notes")); 
$crypt $note['nota']; 
for(
$b=1;$b<11;$b++){ 
$num 11-$b
$chiave  $note[$num]; 
$cnt 0
for (
$i 0$i strlen$crypt ); $i+=2){ 
    
$temp chrhexdecsubstr$crypt$i2) ) ); 
    
$stringa .= $temp $chiave[$cnt strlen($chiave)]; 
    
$cnt++; 

$crypt $stringa

echo 
$stringa
?> 
Ma $stringa non corrisponde alla stringa inserita sapreste dirmi cosa sbaglio?