Location: PHPKode > scripts > PHP Encrypt/Decrypt Text! > keith-armstrong/encrypt.php
<?
/*========================================================================*\
|| ###################################################################### ||
|| # --------- PHP Encrypt/Decrypt Script - Keith Armstrong ----------- # ||
|| # ----------------VERSION: 1.2.6 | 3:52 PM 4/11/2010---------------- # ||
|| # This file may be distributed as long as the Author is given credit # ||
|| # ------- http://www.hotscripts.com/listing/keith-armstrong/ ------- # ||
|| # Note: This script was made by a 16 year old and isn't professional # ||
|| ###################################################################### ||
\*========================================================================*/

// Current Date and Time
	$exedate = date('l F j, Y g:i:s a',time());
// User inputted text to be encrypted/decrypted
// The stripslashes thing is added so that quotes and apostrophes don't have the \ before them and don't corrupt the message content.
	$value = stripslashes($_POST['string']);
// Encrypt or Decrypt?  
	$type = $_POST["type"];
// Encrypt radio button is selected by default
	$encs = "checked";
// Encrypt is the default value
	if ($type == "") {
	$type = "enc";
	}
// Passkey 1	
	$p1 = $_POST["p1"];
// Passkey 2
	$p2 = $_POST["p2"];
// If no passkey is submitted, make it 1
	if ($p1 == "" && $type == "enc") {
		$p1 = "1";
	}
// If no passkey is submitted, make it 1
	if ($p2 == "" && $type == "enc") {
		$p2 = "1";
	}
// Keeps the appearance of 1 but the value is actually X
	if ($p1 == "X" && $type == "dec") {
		$p1 = "1";
	}
// Keeps the appearance of 1 but the value is actually X
	if ($p2 == "X" && $type == "dec") {
		$p2 = "1";
	}

// Passkey encryptions
$passarr = array(
	'1' => 'c4ca4238a0b923820dcc509a6f75849b',
	'2' => 'c81e728d9d4c2f636f067f89cc14862',
	'3' => 'eccbc87e4b5ce2fe28308fd9f2a7ba',
	'4' => 'a87ff679a2f3e71d9181a67b75421',
	'5' => 'e4da3b7fbbce2345d7772b0674a3',
	'6' => '1679091c5a880faf6fb5e6087eb',
	'7' => '8f14e45fceea167a5a36dedd4b',
	'8' => 'c9f0f895fb98ab9159f51fd02',
	'9' => '45c48cce2e2d7fbdea1afc51',
	'X' => 'c4ca4238a0b923820dcc509'
	);
// Encrypted passkeys
	$p1e = strtr($p1,$passarr);
	$p2e = strtr($p2,$passarr);
// Individual characters to be encrypted.  If changed, make sure you change the decrypter as well.
// Encrypted Characters	
$arr = array(
	'a' => 'ù',
	'b' => 'ÿ',
	'c' => 'Ö',
	'd' => 'Ü',
	'e' => '¢',
	'f' => '£',
	'g' => '¥',
	'h' => 'ƒ',
	'i' => 'w',
	'j' => 'u',
	'k' => 'm',
	'l' => 'i',
	'm' => 'o',
	'n' => 'e',
	'o' => 's',
	'p' => '2',
	'q' => 'k',
	'r' => 'j',
	's' => '9',
	't' => 'g',
	'u' => 'r',
	'v' => 'p',
	'w' => 'b',
	'x' => 'd',
	'y' => 'v',
	'z' => 'x',
	'A' => 'V',
	'B' => 'O',
	'C' => 'Q',
	'D' => 'J',
	'E' => 'W',
	'F' => 'R',
	'G' => 'X',
	'H' => 'K',
	'I' => 'C',
	'J' => 'G',
	'K' => 'A',
	'L' => 'E',
	'M' => 'N',
	'N' => 'L',
	'O' => 'S',
	'P' => 'H',
	'Q' => 'I',
	'R' => 'F',
	'S' => 'B',
	'T' => 'D',
	'U' => 'U',
	'V' => 'T',
	'W' => 'P',
	'X' => 'Y',
	'Y' => 'Z',
	'Z' => 'M',
	'1' => 'í',
	'2' => 'ó',
	'3' => 'ú',
	'4' => 'ñ',
	'5' => 'Ñ',
	'6' => 'ª',
	'7' => 'º',
	'8' => '¿',
	'9' => '¬',
	'0' => '½',
	'~' => '¼',
	'`' => '¡',
	'{' => '«',
	'[' => '»',
	'}' => 'æ',
	']' => 'Æ',
	';' => 'ô',
	':' => 'ö'
	);
// Decrypted Characters
$arr2 = array(
	'ù' => 'a',
	'ÿ' => 'b',
	'Ö' => 'c',
	'Ü' => 'd',
	'¢' => 'e',
	'£' => 'f',
	'¥' => 'g',
	'ƒ' => 'h',
	'w' => 'i',
	'u' => 'j',
	'm' => 'k',
	'i' => 'l',
	'o' => 'm',
	'e' => 'n',
	's' => 'o',
	'2' => 'p',
	'k' => 'q',
	'j' => 'r',
	'9' => 's',
	'g' => 't',
	'r' => 'u',
	'p' => 'v',
	'b' => 'w',
	'd' => 'x',
	'v' => 'y',
	'x' => 'z',
	'V' => 'A',
	'O' => 'B',
	'Q' => 'C',
	'J' => 'D',
	'W' => 'E',
	'R' => 'F',
	'X' => 'G',
	'K' => 'H',
	'C' => 'I',
	'G' => 'J',
	'A' => 'K',
	'E' => 'L',
	'N' => 'M',
	'L' => 'N',
	'S' => 'O',
	'H' => 'P',
	'I' => 'Q',
	'F' => 'R',
	'B' => 'S',
	'D' => 'T',
	'U' => 'U',
	'T' => 'V',
	'P' => 'W',
	'Y' => 'X',
	'Z' => 'Y',
	'M' => 'Z',
	'í' => '1',
	'ó' => '2',
	'ú' => '3',
	'ñ' => '4',
	'Ñ' => '5',
	'ª' => '6',
	'º' => '7',
	'¿' => '8',
	'¬' => '9',
	'½' => '0',
	'¼' => '~',
	'¡' => '`',
	'«' => '{',
	'»' => '[',
	'æ' => '}',
	'Æ' => ']',
	'ô' => ';',
	'ö' => ':'
	);
// Password Decryptions
$passarr = array(
	'X' => '1',
	'c4ca4p38a0wsp38p0xcc50sa6f7584sw' => '1',
	'c81n7p8xsx4cpf636f067f8scc1486p' => '2',
	'nccwc87n4w5cnpfnp8308fxsfpa7wa' => '3',
	'a87ff67sapf3n71xs181a67w754p1' => '4',
	'n4xa3w7fwwcnp345x777pw0674a3' => '5',
	'167s0s1c5a880faf6fw5n6087nw' => '6',
	'8f14n45fcnna167a5a36xnxx4w' => '7',
	'csf0f8s5fws8aws15sf51fx0p' => '8',
	'45c48ccnpnpx7fwxna1afc51' => '9'
	);
// If Encrypt is chosen and value entered
	if ($type == "enc" && $value != "") { 
// Encrypt text using array above
	$outcome = strtr($value,$arr);
// Keep encrypt radio button selected
	$encs = "checked";
// Encrypt time and date
	$dout = strtr($exedate,$arr); 
// Add special identifying characters to cut string for decrypt
	$outcome6 = "ÉÅÄ" . $dout . "ÉÅÄ" . $outcome . "~" . $p1e . "~`" . $p2e . "`";
// String length is found to check for changed values in message
	$strln = strlen($outcome6);
// Encoded in base64 to prevent hacking, but still, this script is not recommended for high security stuff
	$strln64 = base64_encode($strln);
// Encrypt the base64 encrypted string
	$strln64e = strtr($strln64,$arr); 
// Special characters to identify string length portion of message
	$outcomep = "ÅÅÅ" . $strln64e . "ÅÅÅ" . $outcome6;
            } else {
// Dummy Variable
            	$nothing = "1";
            }
// If decrypt mode is selected and value is entered
	if ($type == "dec" && $value != "") { 
// Decrypt string with decrypt array from above
		$outcome = strtr($value,$arr2);
// Regular expression match to isolate the passkey, date written, and character count information
		preg_match("/ÉÅÄ(.*)ÉÅÄ/", $value, $m);
		preg_match("/ÅÅÅ(.*)ÅÅÅ/", $value, $l);
// Passkey 1
		preg_match("/~(.*)~/", $value, $p1d);
// Fetches the stored value of passkey 1 decrypted in array[1]
		$p1dr = strtr($p1d[1],$arr2);
// Passkey 2
		preg_match("/`(.*)`/", $value, $p2d);
// Fetches the stored value of passkey 2 decrypted in array[1]
		$p2dr = strtr($p2d[1],$arr2);

// Test variables for debugging, ignore
# echo $p1dr . "<br>";
# echo $p2dr . "<br>";

// Decrypts the passwords using the password decrypt array from above
// Passkey 1 decrypted
		$p1check = strtr($p1dr,$passarr);
// Passkey 2 decrypted
		$p2check = strtr($p2dr,$passarr);

// More test variables, ignore
# echo $p1check . "<br>";
# echo $p2check . "<br>";

// Datemade variable from Array[1] in $l
		$dtm = $m[1];
// Fetches the String Length from the stored array[1] from above
		$num1 = $l[1];
// Decrypts the String using the decryption array from above
		$num1de = strtr($num1,$arr2);
// Decrypts it from it's base 64 encoding
		$numch = base64_decode($num1de);
// Decrypts the date encrypted information
		$datemade = strtr($dtm,$arr2);
// Gets rid of the passkey, date written, and character count information so that the weird symbols won't show up in the output message content
		$outcomu = str_replace("ÅÅÅ" . $num1de . "ÅÅÅ", "", $outcome);
		$outcome0 = str_replace("ÉÅÄ" . $datemade . "ÉÅÄ", "", $outcomu);
		$outcomep = str_replace("~" . $p1dr . "~`" . $p2dr . "`", "", $outcome0);
// Keeps decrypted as the default choice so user doesn't have to repeat steps
		$decs = "checked";
// Makes encrypted null so it won't be selected by default
		$encs = "";
            } else {
// Dummy variable
            	$nothing = "1";
	}
// Tells user if the encrypted code has a passvalue or not
// This one basically says if the type is decryption and a value is applied, and the decrypted forms of the password in the text in passkey 1 and 2 are not equal to 1, than the encrypted text has a passkey
	if ($type == "dec" && $value != "" && $p1dr != "c4ca4p38a0wsp38p0xcc50sa6f7584sw" || $p2dr != "c4ca4p38a0wsp38p0xcc50sa6f7584sw") {
		$key = "Yes";
	}
// If the passkeys 1 & 2 are both 1(which they are by default), then display that there is no passkey
	if ($type == "dec" && $value != "" && $p1dr == "c4ca4p38a0wsp38p0xcc50sa6f7584sw" && $p2dr == "c4ca4p38a0wsp38p0xcc50sa6f7584sw") {
		$key = "No";
	}
// If password 1 doesn't equalt the decrypted password and they select decrypt mode, show error message, and hide the date encrypted from the user.
	if ($p1 != $p1check && $type == "dec") {
		$outcomep = "The Key Code provided was invalid, please enter a valid Key Code to decrypt the Message.";
		$datemade = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
	}
// If password 2 doesn't equalt the decrypted password and they select decrypt mode, show error message, and hide the date encrypted from the user.
	if ($p2 != $p2check && $type == "dec") {
		$outcomep = "The Key Code provided was invalid, please enter a valid Key Code to decrypt the Message.";
		$datemade = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
	}
// If the string length doesn't equal the length that the encoded base 64 string said, than the user most likely tried to hack the text or something, so display text is corrupt.  If you want it to display any way, just comment out the following 4 lines.
	if (strlen($outcomu) != $numch && $type == "dec") {
		$outcomep = "The Encrypted Text Format is Corrupt!";
		$datemade = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
	}
// If the user selects decrypt mode, replace the numbers with X's so the passkey values are hidden.
	if ($type == "dec") {
		$p1 = "X";
		$p2 = "X";
	}
?>
<html>
<head>
<title>Algorithm Encryption</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
</head>
<body bgcolor="black" text="white">
<div align="center"><h1>Algorithm Encryption</h1></div>
<hr>
<center><form action="<? $_SERVER['PHP_SELF'] ?>" method="POST">
<br>Input<br>
Message Content:<br>
<textarea name="string" id="string" rows="7" cols="50"><? echo $value ?></textarea>
<br>
Encrypt<input type="radio" name="type" id="type" value="enc" <? echo $encs ?>> Decrypt<input type="radio" name="type" id="type" value="dec" <? echo $decs ?>>
<br>
1-9
<br>
Key Code: <input type="text" name="p1" value="<? echo $p1 ?>" maxlength="1" size="1" onClick=select() onkeyup="javascript:this.value=this.value.replace(/[^1-9]/g, '');"><input type="text" id="p2" onFocus=select() name="p2" value="<? echo $p2 ?>" maxlength="1" size="1" onkeyup="javascript:this.value=this.value.replace(/[^1-9]/g, '');">
<br>
<input type="submit" value="Generate">
</form>
<br>
<hr>
Output
<br>
Date Encrypted: <input type="text" value="<? echo $datemade ?>" size="35"><br>
Key Code Protected: <input type="text" value="<? echo $key ?>" size="3"><br>
Message Content:<br>
<textarea name="out" id="out" rows="7" cols="50"><? echo $outcomep ?></textarea></center>
<!-- This script was downloaded from http://www.hotscripts.com/listing/keith-armstrong/ -->
<body>
</html>
Return current item: PHP Encrypt/Decrypt Text!