All pastes #473671 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-05-06 11:13 UTC
rendered paste body
<?php
/* Foskasse Fazia te um filho!*/
function asc2bin($inputString, $byteLength=8)
{
	$binaryOutput = '';
	$strSize = strlen($inputString);

	for($x=0; $x<$strSize; $x++)
	{
		$charBin = decbin(ord($inputString{$x}));
		$charBin = str_pad($charBin, $byteLength, '0', STR_PAD_LEFT);
		$binaryOutput .= $charBin;
	}

	return $binaryOutput;
}
function bin2asc($binaryInput, $byteLength=8)
{
	if (strlen($binaryInput) % $byteLength)
	{
		return false;
	}
		$strSize = strlen($binaryInput);
	$origStr = '';
	for($x=0; $x<$strSize; $x += $byteLength)
	{
		$charBinary = substr($binaryInput, $x, $byteLength);
		$origStr .= chr(bindec($charBinary)); 
	}
	return $origStr;
}
?>

<?
/* Exemplo */
$inputString = "André Duarte!";
$binOut =  asc2bin($inputString);
$ascOut = bin2asc($binOut);
echo $binOut, $ascOut;
?>