All pastes #932616 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-03-07 21:18 UTC
rendered paste body
<?php


/// This is the message used to test the decoder
$message = 

"0x0152414435212135463170524144352122355631704B4C5F472122367B294855444A54372B457721544B210452414435212335562F264B4C5F47212336

7B294855444A50372B46212155213B0452414435212435562F2652414435212535562F264B4C5F472124367B294855444A4E372B457921552456047077725

821473E233C6D21215A4C027077725821473E233C6D21215A4C";

// Remove the "0x", which isn't important
$message = substr($message, 2);

// Next, we check to see if the message has only the non-control types
// at the end or "only"
$controlcheck = substr($message, -2);
if ($controlcheck != '02' && $controlcheck != '03' && $controlcheck != '04' && $controlcheck != '05'){
	echo "There is a message at the end.";
}


// This sets a variable to increment when going 
//through all the bytes looking for control character

$bytechecks = 0;

// While this variable is less than 144 bytes (188 characters) we perform some routines
while ($bytechecks != 188){

// This creates an array for the messages, by going through every 2 bytes.
$messages[] = substr($message, 2, 2);

// This is for each part of the message, as just one variable
$messagepart = substr($message, 2, 2);

// This is for "potential messages", a work-around to add all final messages to an array
$potentialmessage[] = substr($message, 2, 2);

// This will eacho each message part, without spaces to make a fake representation, on-screen of
// an actual "message" being decoded.
echo $messagepart;


// Here is where we check if a byte is 04, one of the control characters used.



// If the byte is a different control character, '02' and '03', we perform another task that is similar
// to the one above.

if ($messagepart == '02'){


	$potentialmessage2[] = implode('', $potentialmessage);
	echo "<br>";
	unset($potentialmessage);

}

if ($messagepart == '03'){

	$potentialmessage2[] = implode('', $potentialmessage);
	echo "<br>";
	unset($potentialmessage);

}

if ($messagepart == '04'){

	// If the byte matches "04", we create another potential message array, 
	// and smash all the potential message parts together.
	$potentialmessage2[] = implode('', $potentialmessage);
	// This will echo a break after the potential message has been gone through.
	echo "<br>";
	// Then we unset the potential message array to begin working with a new one.
	unset($potentialmessage);
	}


if ($messagepart == '05'){

	$potentialmessage2[] = implode('', $potentialmessage);
	echo "<br>";
	unset($potentialmessage);

}

// This removed two from the message, and then increases the counter.
$message = substr($message, 2);
$bytechecks += 1;
}

echo "<br>";


// This echoes each message that we have recieved.
foreach ($potentialmessage2 as $msg){
	
	// Set the "small length"
	$smaller = 20;

	// Here we check for smaller messages that might be hidden inside.
	if (substr($msg, -2) == '02'){
		$max = 14;
		$length = strlen($msg) / 2 - 1;
		while ($length > $max){
			// Another message inside (or multiple)
			$smallermessage[] = substr($msg, 0, $smaller);
			$msg = substr($msg, $smaller);
			$length = strlen($msg) / 2 - 1;
			} 
	}

	// Here we check for smaller messages that might be hidden inside.
	if (substr($msg, -2) == '03'){
		$max = 18;
		$length = strlen($msg) / 2 - 1;
		//echo $length;
		while ($length > $max){
			// Another message inside (or multiple)
			$smallermessage[] = substr($msg, 0, $smaller);
			$msg = substr($msg, $smaller);
			$length = strlen($msg) / 2 - 1;
			} 
	}

	// Here we check for smaller messages that might be hidden inside.
	if (substr($msg, -2) == '04'){
		$max = 22;
		$length = strlen($msg) / 2 - 1;
		//echo $length;
		while ($length > $max){
			// Another message inside (or multiple)
			$smallermessage[] = substr($msg, 0, $smaller);
			$msg = substr($msg, $smaller);
			$length = strlen($msg) / 2 - 1;
			} 
	}

	// Here we check for smaller messages that might be hidden inside.
	if (substr($msg, -2) == '05'){
		$max = 26;
		$length = strlen($msg) / 2 - 1;
		//echo $length;
		while ($length > $max){
			// Another message inside (or multiple)
			$smallermessage[] = substr($msg, 0, $smaller);
			$msg = substr($msg, $smaller);
			$length = strlen($msg) / 2 - 1;
			} 
	}

	echo "<b>".$msg."</b><br>";
}

foreach ($smallermessage as $smallmsg){
echo "<b>".$smallmsg."</b><br>";

}
?>