/    Sign up×
Community /Pin to ProfileBookmark

Illegals produced after encode/decode

Not really sure where these are coming from, but they’re being produced
after I try to encode something,

[code]
things like manufacterer’s
turn into manufacturer�s

and degree’s for fahrenheit/celsius
113° F (45° C) have that A after
them. Evert time I hit execute after,
it adds even more

113���° F (45���° C)
[/code]

What the hell happened? This is driving me bat**** trying to convert all
this to htmlentities per case….

Here’s my coding.

[code=php]
<?php
// Global defines
define(‘VERSION’, ‘2.1e’);
define(‘SALT’, $salt);

# var list
$sp ='<x style=”margin:5&#37;” />’;
$salt = ‘o_0 Neko%$Mata 2051’;

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)));
}

function fixoutput($str){
$good[] = 9; #tab
$good[] = 10; #nl
$good[] = 13; #cr
for($a=32;$a<127;$a++){
$good[] = $a;
}
$len = strlen($str);
for($b=0;$b < $len+1; $b++){
if(in_array(ord($str[$b]), $good)){
$newstr .= $str[$b];
}//fi
}//rof
return $newstr;
}

?>
<!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’];
fixoutput($output);

# Trying to remove illegals, hasn’t worked yet
$pattern = array ( “#&#176;#”, “#&#194;#”, “#&#226;&#8364;&#8482;#”);
$replace = array ( ‘and#176;’, ”, ”’);
$output = preg_replace($pattern, $replace, $output);

$sub_directory = “/prl/”;
$output = str_replace(“r”,””,$output);
$output = str_replace(“n”,””,$output);
$output = str_replace(“/lighting/”,$sub_directory,$output);

$output = encrypt($output);
$output = chunk_split($output, 85, “‘.rn'”);

$pattern = array(
‘//’, # Backslashes
‘#.s*’Z#’ # Trail Ending :: Added lastline switch Z
);

$replace = array(
”, # Blank
‘;’ # End of Line
);

$output = preg_replace($pattern, $replace, $output);
echo “<br /><b style=’color:red;’>Cipher:</b><br />rn”;
echo “<textarea style=’width:99.3%;background-color:#000;color:#0f0;’>’$output</textarea>rn”;
echo “<br />rn”;

$input = decrypt($output);
$input = stripslashes($input);
echo “<br /><b style=’color:red;’>Rendered:</b>rn”;
echo “<div style=’color:#0f0;’> $input </div><br />”;
break;

case ‘decrypt’:

$output = decrypt($_POST[‘phpCode’]);

/* replaces vibration = vibr /ation, no good yo. */
$pattern = array(“#<br>#”,”#<br / />#”, “#<<#”, “#>>#”);
$replace = array(“<br />”,”<br />”, “<“, “>”);

$output = preg_replace($pattern, $replace, $output);
$input = htmlspecialchars(stripslashes($output));
echo “<br /><b style=’color:red;’>Source Code:</b><br />rn”;
echo “<textarea style=’width:99.3%;background-color:#000;color:#0f0;’> $input </textarea>rn”;
echo “<br />rn”;

$output = stripslashes($output);
echo “<br /><b style=’color:red;’>Rendered:</b>rr”;
echo “<div style=’color:#0f0; margin-right:-25px’>$output</div><br />r”;

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();” /><?=$sp;?>
<input class=”button” type=”submit” value=”Execute Code” /><?=$sp;?>
<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><?=$sp;?><b style=”color:#fff;margin-left:7px;”>
<?=”Salt: &nbsp;r”?>
<?=”<textarea style=’position:relative;top:4px;width:22%;height:18px;background-color:#000;color:#0f0;’>&nbsp;$salt</textarea>r”?>
</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>&nbsp;
<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 />
&copy; 2oo9 – jd!<a href=”http://omnisistem.com” target=”_blank” class=”credits”>OmniSistem</a><br />
</div>
</body>
</html>
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@linewireDec 18.2009 — The last time I had a somewhat similar issue it had to do with my document being showing ISO rather than UTF-8
×

Success!

Help @ehime spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...