So I have this little encryptor that I wrote, and I am having some
issues with the output on my last line. I would like it to echo '; so
I can just copy paste it straight across, instead it echo's out '.\r\n'
Issue is, since this is the last line, if I do preg_replace it might remove
all other concats and such. Oh the horror's, lol! There are a few other
things that I am toying with in here too, preg_replace <br> /w <br />
and etc, you can see them inside in the find and replace, none of those
really work, so you can ignore them, or .... ? PROFIT! ha, j/k
Anyway, I tried using preg_replace to match and replace the last line
with no luck. Anyone take a look and see if they have a better answer
to this? Thanks guys, here's the code, and a blank output to compare.
Blank output
'ppOyiN99rlsXV2QCdkOSMNt3xM16hx4k1hYuVK9DSJE='.
'
How blank output should look:
'ppOyiN99rlsXV2QCdkOSMNt3xM16hx4k1hYuVK9DSJE=';
Program:
<?php
// Global defines
define('VERSION', '1.2c');
define('SALT', $salt);
$salt = 'MY.SALT.HERE';
function encrypt($text) {
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT, $text,
MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
}
function decrypt($text) {
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT, base64_decode($text),
MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MCrypt v<?=VERSION ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="J.d. (Jon Daniel)" />
<meta name="copyright" content="http://ehime.deviantart.com" />
<meta name="Keywords" content=""/>
<meta name="Description" content="Speed (de)MCrypt files" />
<style type="text/css">
/* <![CDATA[ */
body{color:#114;background-color:#333;font-family:Verdana;width:60%;}
h2{color:#eee;padding:6px;font-size:16px;}div{width:98%;padding:6px;margin:6px;}
form{height:360px;}
.button {margin-top:-25px;}
div.output{color:#114;background-color:#ccc;border:1pxdashed#fff;font-size:10px;}
div.input{height:50%;background-color:#000;border:1pxdashed#0f0;}
textarea.code{width:100%;height:300px;color:#0f0;background-color:#000;border:none;}
input{background-color:#eee;color:#262;border:2pxsolid#ccc;font-weight:bold;}a.credits{color:#9f9;}
div.credtis{color:#bbb;margin-top:50px;font-size:10px;}
/* ]]> */
</style>
<script type="text/javascript">
function clearCode() {
var srcCode = document.getElementById('phpCode');
if (srcCode) { srcCode.value = ""; } }
</script>
</head>
<body>
<div class="output" style="background-color:black">
<?php
switch ($_POST['crypt']) {
case 'encrypt':
$output = $_POST['phpCode'];
$find = array( "°", "•", " < ", chr(10), chr(13),
# Replace PHP /w Null
"<?=$nwl;?>",
'<?php include ($_SERVER[\'DOCUMENT_ROOT\'] . "/php/global2.php"); ?>',
"<? $dir = 'images/products/laser/sub/';?>",
);
$replace = array( "°", "•", " < ", "", "",
# Replace PHP /w Null
"<img alt='' class=\"nwl\" src=\"http://omnisistem.com/images/symbols/nwl.jpg\">",
"",
"",
);
$output = str_replace($find, $replace, $output);
$output = encrypt($output);
$output = chunk_split($output, 85, "'.\r\n'");
$pattern = '//';
$replace = '';
# preg_replace($pattern, $replace, $output);
echo "<br /><b style='color:red;'>Cipher:</b><br />";
echo "<textarea style='width:99.3%;background-color:#000;color:#0f0;'>'$output</textarea>";
echo "<br />";
$input = $_POST['phpCode'];
$input = stripslashes($input);
echo "<br /><b style='color:red;'>Rendered:</b>";
echo "<div style='color:#0f0; margin:-25px'>$input</div><br />";
break;
case 'decrypt':
$output = decrypt($_POST['phpCode']);
$find = array( "<br>", );
$replace = array( "<br />", );
$output = str_replace($find, $replace, $output);
$input = htmlspecialchars(stripslashes($output));
echo "<br /><b style='color:red;'>Source Code:</b><br />";
echo "<textarea style='width:99.3%;background-color:#000;color:#0f0;'>$input</textarea>";
echo "<br />";
$output = stripslashes($output);
echo "<br /><b style='color:red;'>Rendered:</b>";
echo "<div style='color:#0f0; margin:-25px'>$output</div><br />";
break;
}
?>
</div>
<div class="input"><form action="<?=$_SERVER['PHP_SELF'] ?>" method="post">
<div style='margin:5px 0;'>
<input class="button" type="button" value="Clear Code" onclick="javascript:clearCode();" />
<input class="button" type="submit" value="Execute Code" /><x style="margin:5%" />
<b style="color:#fff; border:1px dashed #0f0; padding:5px;"><input type="radio" name="crypt" value="encrypt" checked="checked" /> +
<input type="radio" name="crypt" value="decrypt" /> - </b><x style="margin:5%" /><b style="color:#fff;margin-left:7px;">
<?="Salt: "?>
<?="<textarea style='position:relative;top:4px;width:22%;height:18px;background-color:#000;color:#0f0;'> $salt</textarea>"?>
</b>
</div>
<textarea id="phpCode" name="phpCode" class="code" rows="0" cols="0"><?php
if (isset($_POST['phpCode'])) echo htmlentities(stripslashes($_POST['phpCode'])) ?></textarea><br /><br />
</form>
</div>
<div class="credtis">
<strong>MCrypt v<?=VERSION ?></strong>
<a href="http://omnisistem.com/" target="_blank" class="credits">(About)</a><br />
---<br />
Disclaimer:<br />
Use at your own risk. No warranty implied.<br />
<br />
© 2oo9 - jd!<a href="http://omnisistem.com" target="_blank" class="credits">OmniSistem</a><br />
</div>
</body>
</html>