0

I like PHP, its my favorite language when it comes to web-scripting, and from time to time i like to just see what i can come up with... so i was messing around today and came up with this:

<?PHP

function string_to_ascii($string){
	$ascii = NULL;
	for ($i = 0; $i < strlen($string); $i++){
		$ascii .= ord($string[$i]);
	}
	return($ascii);
}

function enc($password){
	$keycode_base64=base64_encode("testkeycode");
	$password_base64=base64_encode($password);
	$keycode_ascii=string_to_ascii($keycode_base64);
	$password_ascii=string_to_ascii($password_base64);
	$keycode=NULL;
	$i=0;
	$offset=0;
	while($offset<strlen($keycode_ascii)&&$i<strlen($password_ascii)){
		$keycode .= $keycode_ascii[$offset] + $password_ascii[$i];
		if($offset<strlen($keycode_ascii))
			{$offset++;}
			else
			{$offset=0;}
		if($i<strlen($password_ascii))
			{$i++;}
			else
			{$i=0;}
	}
	return($keycode);
}

	$keycode_base64=base64_encode("testkeycode");
	$password_base64=base64_encode("testpassword");
	$keycode_ascii=string_to_ascii($keycode_base64);
	$password_ascii=string_to_ascii($password_base64);

$enc = enc("testpassword");

echo "$keycode_base64<br>$password_base64<br>$password_ascii<br>$keycode_ascii<br>$enc";


?>

I assume if you are perusing this sub-forum you can figure out what this is meant to do... i'm not even sure this would do what it is intended to do very well...

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Merlin33069
0

So what's the question/objective or is this just a general chat topic? L@@ks like a bunch of random strings being displayed from what I can see.

0

ah, OK, well this is more of a roundabout encryption function... one that i don't even know if i can decrypt yet as i haven't tried... I'm not sure its secure, basically you can put in two strings... you could use the user-name as the key-code, or the site name or whatever, then the program takes the password and offsets the key-codes numbers with the numbers from the password.... from what i can see it *might* be unacceptable by reversing the offsets and subtracting... not sure, like i said just something to waste my free time with :D

0

It appears to be secure and with a few tweaks could be more secure than sha1. But I would recommend doing more than just adding the numbers on line 20. Perhaps using a binary operator would be better.

0

I've changed it a decent bit since then (no pun intended) and concluded that because of the switch to ASCII, i have to keep each letter separate, at least until the end... so here is the new code

<?PHP
$password = "Pa55w0rdzAr3Fun";
$keycode = "TimmCo_Test_Keycode";

function enc($password, $keycode){
	$keycode_base64=base64_encode($keycode);
	$password_base64=base64_encode($password);
		for ($i = 0; $i < strlen($password_base64); $i++)
		{
			$password_ascii[] = ord($password_base64[$i]);
		}
		for ($i = 0; $i < strlen($keycode_base64); $i++)
		{
			$keycode_ascii[] = ord($keycode_base64[$i]);
		}
	$i=0;
	$offset=0;
	while($offset<sizeof($keycode_ascii)&&$i<sizeof($password_ascii)){
		$keycode_ascii[$offset] = $keycode_ascii[$offset] + $password_ascii[$i];
		if($offset<sizeof($keycode_ascii))
			{$offset++;}
			else
			{$offset=0;}
		if($i<sizeof($password_ascii))
			{$i++;}
			else
			{$i=0;}
	}
	return($keycode_ascii);
}

$keycode_base64=base64_encode($keycode);
$password_base64=base64_encode($password);
for ($i = 0; $i < strlen($password_base64); $i++)
{
	$password_ascii[] = ord($password_base64[$i]);
}
for ($i = 0; $i < strlen($keycode_base64); $i++)
{
	$keycode_ascii[] = ord($keycode_base64[$i]);
}
echo "$keycode<br>$password<br>$keycode_base64<br>$password_base64<br>";

foreach ($keycode_ascii as $value) {
echo $value . ", ";
}
echo "<br>";
foreach ($password_ascii as $value) {
echo $value . ", ";
}
echo "<br>";
$keycode = enc($password, $keycode);

foreach ($keycode as $value) {
echo decbin($value) . ", ";
}

$offset = 0;
while($offset<sizeof($keycode)){

	$keycode[$offset] = decbin($keycode[$offset]);
	$strlen = strlen($keycode[$offset]);
	switch($strlen){
		case(1):
			$keycode[$offset] = "0000000" . $keycode[$offset];
			break;
		case(2):
			$keycode[$offset] = "000000" . $keycode[$offset];
			break;
		case(3):
			$keycode[$offset] = "00000" . $keycode[$offset];
			break;
		case(4):
			$keycode[$offset] = "0000" . $keycode[$offset];
			break;
		case(5):
			$keycode[$offset] = "000" . $keycode[$offset];
			break;
		case(6):
			$keycode[$offset] = "00" . $keycode[$offset];
			break;
		case(7):
			$keycode[$offset] = "0" . $keycode[$offset];
			break;
		case(9):
			die("ERROR IN length OF BINARY DATA");
			break;
	}
	$offset++;
}
echo "<br><br>";
foreach ($keycode as $value) {
echo $value . "<br>";
}
?>

and its output at the moment:

TimmCo_Test_Keycode
Pa55w0rdzAr3Fun
VGltbUNvX1Rlc3RfS2V5Y29kZQ==
UGE1NXcwcmR6QXIzRnVu
86, 71, 108, 116, 98, 85, 78, 118, 88, 49, 82, 108, 99, 51, 82, 102, 83, 50, 86, 53, 89, 50, 57, 107, 90, 81, 61, 61,
85, 71, 69, 49, 78, 88, 99, 119, 99, 109, 82, 54, 81, 88, 73, 122, 82, 110, 86, 117,
10101011, 10001110, 10110001, 10100101, 10110000, 10101101, 10110001, 11101101, 10111011, 10011110, 10100100, 10100010, 10110100, 10001011, 10011011, 11100000, 10100101, 10100000, 10101100, 10101010, 1011001, 110010, 111001, 1101011, 1011010, 1010001, 111101, 111101,

10101011
10001110
10110001
10100101
10110000
10101101
10110001
11101101
10111011
10011110
10100100
10100010
10110100
10001011
10011011
11100000
10100101
10100000
10101100
10101010
01011001
00110010
00111001
01101011
01011010
01010001
00111101
00111101

I plan on splitting each of the binary sets sequences in half, then taking the resulting binary back into decimal, then from ASCII into text, and then converting back FROM base64 into regular text... and if all goes well through testing I'm going to call it finished... and then move on to something new probably...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.