<html>
<body>
<h2>Encoding and Hashes</h2>
<form action="encode.php" method="post">
<p>Text to be hashed / encrypted: <input type="text" name="tobehashed"></p>
</form>
<?php
$tobehashed = $_POST['tobehashed'];
function str2bin($str, $mode=0) {
$out = false;
for($a=0; $a < strlen($str); $a++) {
$dec = ord(substr($str,$a,1));
$bin = '';
for($i=7; $i>=0; $i--) {
if ( $dec >= pow(2, $i) ) {
$bin .= "1";
$dec -= pow(2, $i);
} else {
$bin .= "0";
}
}
/* Default-mode */
if ( $mode == 0 ) $out .= $bin;
/* Human-mode (easy to read) */
if ( $mode == 1 ) $out .= $bin . " ";
/* Array-mode (easy to use) */
if ( $mode == 2 ) $out[$a] = $bin;
}
return $out;
}
function strhex($string)
{
$hex="";
for ($i=0;$i<strlen($string);$i++)
$hex.=(strlen(dechex(ord($string[$i])))<2)? "0".dechex(ord($string[$i])): dechex(ord($string[$i]));
return $hex;
}
if(isset($tobehashed))
{
echo "<br /><p><b>Encodings of '".$tobehashed."'</b></p>";
echo "<p>rot13: ".str_rot13($tobehashed)."</p>";
echo "<p>base64: ".base64_encode($tobehashed)."</p>";
echo "<p>binary: ".str2bin($tobehashed)."</p>";
echo "<p>hex: ".strhex($tobehashed)."</p>";
echo "<br /><p><b>Hashes of '".$tobehashed."'</b></p>";
$algos = hash_algos();
foreach($algos as $algo)
{
echo "<p>".$algo.": ".hash($algo, $tobehashed)."</p>";
}
}
?>
</body>
</html>