Ian N wrote:
I've had to quickly servers and need to turn an ASP script
into PHP, i got the original script from: -
http://www.4guysfromrolla.com/webtech/012000-1.shtml
Does anyone know of a PHP version of this? otherwise it's gonna be a
few hours sifting through it and converting it line by line.
Hours? How about ten minutes? The script given at
http://www.4guysfromrolla.com/webtech/110599-1.2.shtml
translates as follows:
$g_CryptThis = "Now is the time for all good men to come to the aid of
their country.";
$g_KeyLocation = "key.txt";
$g_Key = substr(ReadKeyFromFile($g_KeyLocation), 0,
strlen($g_CryptThis));
echo "<p>ORIGINAL STRING: ", $g_CryptThis, "<p>";
echo "<p>KEY VALUE: ", $g_Key, "<p>";
echo "<p>ENCRYPTED CYPHERTEXT: ", EnCrypt($g_CryptThis), "<p>";
echo "<p>DECRYPTED CYPHERTEXT: ", DeCrypt(EnCrypt($g_CryptThis)),
"<p>";
function EnCrypt($strCryptThis) {
global $g_Key;
for ($i = 0; $i < strlen($strCryptThis); $i++) {
$iKeyChar = ord($g_Key{$i});
$iStringChar = ord($strCryptThis{$i});
// *** uncomment below to encrypt with addition,
// $iCryptChar = $iStringChar + $iKeyChar;
$iCryptChar = $iKeyChar ^ $iStringChar;
$strEncrypted = $strEncrypted . chr($iCryptChar);
}
return $strEncrypted;
}
function DeCrypt($strEncrypted) {
global $g_Key;
for ($i = 0; $i < strlen($strEncrypted); $i++) {
$iKeyChar = ord($g_Key{$i});
$iStringChar = ord($strEncrypted{$i});
// *** uncomment below to decrypt with subtraction
// $iDeCryptChar = $iStringChar - $iKeyChar;
$iDeCryptChar = $iKeyChar ^ $iStringChar;
$strDecrypted = $strDecrypted . chr($iDeCryptChar);
}
return $strDecrypted;
}
function ReadKeyFromFile($strFileName) {
$key = file_get_contents($strFileName);
$key = str_replace("\r", '', $key);
$key = str_replace("\n", '', $key);
return $key;
}
Cheers,
NC