Hello so i have this encode/decode script
<?php
// Encoding key
$key = "vns98ogavna5489hverz9np950yhz9gzx89fghjv9pv4598hj";
function encode($string,$key) {
$key = sha1($key);
$strLen = strlen($string);
$keyLen = strlen($key);
for ($i = 0; $i < $strLen; $i++) {
$ordStr = ord(substr($string,$i,1));
if ($j == $keyLen) { $j = 0; }
$ordKey = ord(substr($key,$j,1));
$j++;
$hash .= strrev(base_convert(dechex($ordStr + $ordKey),16,36));
}
return $hash;
}
function decode($string,$key) {
$key = sha1($key);
$strLen = strlen($string);
$keyLen = strlen($key);
for ($i = 0; $i < $strLen; $i+=2) {
$ordStr = hexdec(base_convert(strrev(substr($string,$i,2)),36,16));
if ($j == $keyLen) { $j = 0; }
$ordKey = ord(substr($key,$j,1));
$j++;
$hash .= chr($ordStr - $ordKey);
}
return $hash;
}
?>
so what i am trying to do is grab a file and decode the 2nd and 3rd words only of each line.
There is 4 words per line. This is the script i made to remove the first line and remove the first and last words on each sentence. Then print the page, all which works well. the problem i am having is to decode the remaining words all at once.
<?php
// removes the first line
$hideStartWith = "<";
$replaceWith = "";
$file = "./pass_users.php";
$f = fopen($file, "r");
while ( $line = fgets($f, 1000) ) {
if(substr($line, 0, strlen($hideStartWith)) === $hideStartWith){
$line = $replaceWith;
}
// replace word
$test = str_replace("||","       ",$line);
// removes last word in string
$b = preg_replace('~\\s+\\S+$~', '', $test);
// removes first word in string
$q = substr(strstr($b," "), 1);
print nl2br($q);
}
?>
i can decode single words just fine.
example
Encode:
<?php echo encode("Please Encode Me!","This is a key"); ?>
Result:
p3e4e4241674d2r4m4i5o464a4f2p3k5c2
Decode:
<?php echo decode("p3e4e4241674d2r4m4i5o464a4f2p3k5c2","This is a key"); ?>
Result:
Please Encode Me!
Thank you