from what i've done below 'not done' just a test it works, the problem comes when multiple letters are inputted that are the same. if i type "haha" it output: aahh and decoded as output: oobb. because it loops from the start to begging. any quick fix anybody can see in this? right now i cannot see straight ty for all your help
This is not in anyway done, i just wondered how to make this work. I know the problem, however it seems funky to me maybe with possibly more conditional statements so that it skips?
Code:
$base=Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
$enc=Array("o","p","q","r","s","t","a","b","c","d","e","f","g","n","u","v","w","x","y","z","h","i","j","k","l","m");
//setup get vars test
$encc=$_GET["e"];
$decc=$_GET["d"];
if ($encc!="") {
echo "<b>You requested: $encc.</b>";
$input=str_split($encc);
$c=count($input);
$enc_done=Array();
for ($x=0;$x<=count($base);$x++) {
for ($y=0;$y<count($enc);$y++) {
if ($base[$x]==$input[$y]) {
$ans.=$enc[$x];
$enc_done[]=$enc[$x];
}
}
}
echo "<p>output: $ans";
echo "<hr>decode---";
for ($x=0;$x<=count($base);$x++) {
for ($y=0;$y<count($enc);$y++) {
if ($enc[$x]==$enc_done[$y]) {
$ansd.=$base[$x];
}
}
}
echo "<p>output: $ansd";
}
This is not in anyway done, i just wondered how to make this work. I know the problem, however it seems funky to me maybe with possibly more conditional statements so that it skips?