<?php
/**
*@description: ROT13 algorithm to encrypt/decrypt strings with one single function
*/
function rot13Modified ($str) {
$MNLTTRASCII = 97;
// min letter ascii
$MXLTTRASCII = 122;
// max letter ascii
$MNCLTTRASCII = 65;
// min capital letter ascii
$MXCLTTRASCII = 90;
// max capital letter ascii
$MNNRASCII = 48;
// min number ascii
$MXNRASCII = 57;
// max number ascii
$special['@'] = "_";
$special['.'] = "-";
$special[' '] = "$";
$special['/'] = '\\';
$new = "";
for ($i = 0; $i < strlen($str); $i++) { if (($MNNRASCII <= ord($str[$i])) && (ord($str[$i]) <= $MXNRASCII)) { // numeric
$nr = ord($str[$i]) + (($MXNRASCII - $MNNRASCII + 1) / 2); // (($MXNRASCII - $MNNRASCII + 1) / 2) = half of total numbers
if ($nr > $MXNRASCII) {
$diff = $nr % $MXNRASCII;
$nr = $MNNRASCII - 1 + $diff;
}
} else if (($MNLTTRASCII <= ord($str[$i])) && (ord($str[$i]) <= $MXLTTRASCII)) { // lowercase letter
$nr = ord($str[$i]) + (($MXLTTRASCII - $MNLTTRASCII + 1) / 2);; if ($nr > $MXLTTRASCII) {
$diff = $nr % $MXLTTRASCII;
$nr = $MNLTTRASCII - 1 + $diff;
}
} else if (($MNCLTTRASCII <= ord($str[$i])) && (ord($str[$i]) <= $MXCLTTRASCII)) { // capital letter
$nr = ord($str[$i]) + (($MXCLTTRASCII - $MNCLTTRASCII + 1) / 2);; if ($nr > $MXCLTTRASCII) {
$diff = $nr % $MXCLTTRASCII;
$nr = $MNCLTTRASCII - 1 + $diff;
}
// maybe it exists as key in the special token array
$nr = ord($special[$str[$i]]); // set the value of the key as number (ascii)
} else if (in_array($str[$i], $special)) { // maybe it exists as value in the special token array - opposite of the previous else if
$nr = ord($tmp[$str[$i]]); }
}
// reverse the string - not necessary, but this will blow their (hacking) socks off...
return $new;
}
?>