Nu har jeg godt nok givet point, pga det virkede, og 5 til mathias pga han skrev det med at jeg skulle slette det der. Som der dog alligevel allerede stod.
Men problemet kommer så, når jeg vil have de 2 funktioner på hver deres side. Krypteren virker fint, men dekrypteren virker ikke...
Min kode (håber stadig i vil hjælpe)
<?php
$send = $_POST['send'];
if ($send == "valid") {
$sendt = $_POST['sendt'];
if ($sendt == 1) {
$besked = $_POST['besked'];
$besked2 = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","y","r","s","t","u","v","w","x","y","z","æ","ø","å","0","1","2","3","4","5","6","7","8","9");
$besked3 = array("r","1","t","0","v","p","å","3","s","o","ø","i","u","b","æ","2","c","4","e","k","5","h","a","q","c","j","f","z","m","n","6","7","x","d","g","w","9","y","8");
/*shuffle only to make it unpredictable*/
shuffle($besked2);
shuffle($besked3);
/*create the krypting and dekrypting arrays*/
$krypt=array_combine($besked2,$besked3);
$dekrypt=array_combine($besked3,$besked2);
for($i=0;$i<strlen($besked);$i++){
$besked[$i]=$krypt[$besked[$i]];
}
print('enkrypted message:'.$besked.'<br>');
for($i=0;$i<strlen($besked);$i++){
$besked[$i]=$dekrypt[$besked[$i]];
}
#print('dekrypted message:'.$besked);
} elseif ($sendt == 2) {
$besked = $_POST['besked'];
$besked2 = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","y","r","s","t","u","v","w","x","y","z","æ","ø","å","0","1","2","3","4","5","6","7","8","9");
$besked3 = array("r","1","t","0","v","p","å","3","s","o","ø","i","u","b","æ","2","c","4","e","k","5","h","a","q","c","j","f","z","m","n","6","7","x","d","g","w","9","y","8");
/*shuffle only to make it unpredictable*/
shuffle($besked2);
shuffle($besked3);
/*create the krypting and dekrypting arrays*/
$krypt=array_combine($besked2,$besked3);
$dekrypt=array_combine($besked3,$besked2);
for($i=0;$i<strlen($besked);$i++){
$besked[$i]=$krypt[$besked[$i]];
}
#print('enkrypted message:'.$besked.'<br>');
for($i=0;$i<strlen($besked);$i++){
$besked[$i]=$dekrypt[$besked[$i]];
}
print('dekrypted message:'.$besked);
}
} else {
echo '<form action="hej2.php" method="post">
<input type="hidden" name="send" value="valid">
Krypter<input type="radio" name="sendt" value="1"><br>
Dekrypter<input type="radio" name="sendt" value="2"><br>
<textarea name="besked"></textarea><br>
<input type="submit">
</form>';
}
?>