Jump to content

Creating a simple formula


KingOfHeart

Recommended Posts

I'm using sockets to send/receive data to a website. I don't want anyone to be able to be able to read it. For now I'm using the base64 method.

For the most part if they crack it, it's no big deal. However when it comes to submitting a score or telling the site that a level was tested it can be.

 

So for my score submitting and telling if a file was tested, I'm using a math formula.

 

I use a math formula to create a code based on the design of the file and the score your submitting.

If the code gets cracked, they will still have to figure out the code if they wish to submit a fake score.

 

Are there any math formula methods I can use to make it hard to figure out?

Is there another type of encryption formula that can be created for any language (so mcrypt is out)?

 

BTW here's how my script looks for the base64 for my game(which uses pawn)

 

Encode64(string[])
{
new pad, length, length2, block;
length = strlen(string);

// Get the padding we need
if((length % 3) == 0)
{
	pad = 0;
	block = length / 3;
}
else
{
	pad = 3 - (length % 3);
	block = (length + pad) / 3;
}
length2 = length + pad;

// Create a string with the padding
new source[300];
for(new x = 0; x < length2; x++)
{
	if(x < length)
		source[x] = string[x];
	else
		source[x] = 0;
}

// Convert to 64 bit
new b1, b2, b3;
new temp, temp1, temp2, temp3, temp4;
new length3 = block * 4;
new buffer[300], result[300];

for(new x = 0; x < block; x++)
{
	b1 = source[x*3];
	b2 = source[x*3+1];
	b3 = source[x*3+2];

	temp1 = ((b1 & 252)>>2);

	temp = ((b1 & 3)<<4);
	temp2 = ((b2 & 240)>>4);
	temp2 += temp;

	temp = ((b2 & 15)<<2);
	temp3 = ((b3 & 192)>>6);
	temp3 += temp;

	temp4 = (b3 & 63);

	buffer[x*4] = temp1;
	buffer[x*4+1] = temp2;
	buffer[x*4+2] = temp3;
	buffer[x*4+3] = temp4;
}
for(new x = 0; x < length3; x++)
{
	result[x] = encstring[buffer[x]];
}

if(pad > 0)
	result[length3-1] = '=';
if(pad == 2)
	result[length3-2] = '=';
strcpy(output, result);
}

Link to comment
https://forums.phpfreaks.com/topic/183929-creating-a-simple-formula/
Share on other sites

This is the code on the client side for the encrypting and decrypting which uses pawn.

 

new encstring[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
//Encoder Function
Encode64(string[])
{
new pad, length, length2, block;
length = strlen(string);

// Get the padding we need
if((length % 3) == 0)
{
	pad = 0;
	block = length / 3;
}
else
{
	pad = 3 - (length % 3);
	block = (length + pad) / 3;
}
length2 = length + pad;

// Create a string with the padding
new source[300];
for(new x = 0; x < length2; x++)
{
	if(x < length)
		source[x] = string[x];
	else
		source[x] = 0;
}

// Convert to 64 bit
new b1, b2, b3;
new temp, temp1, temp2, temp3, temp4;
new length3 = block * 4;
new buffer[300], result[300];

for(new x = 0; x < block; x++)
{
	b1 = source[x*3];
	b2 = source[x*3+1];
	b3 = source[x*3+2];

	temp1 = ((b1 & 252)>>2);

	temp = ((b1 & 3)<<4);
	temp2 = ((b2 & 240)>>4);
	temp2 += temp;

	temp = ((b2 & 15)<<2);
	temp3 = ((b3 & 192)>>6);
	temp3 += temp;

	temp4 = (b3 & 63);

	buffer[x*4] = temp1;
	buffer[x*4+1] = temp2;
	buffer[x*4+2] = temp3;
	buffer[x*4+3] = temp4;
}
for(new x = 0; x < length3; x++)
{
	result[x] = encstring[buffer[x]];
}

if(pad > 0)
	result[length3-1] = '=';
if(pad == 2)
	result[length3-2] = '=';
strcpy(output, result);
}

// Decoder Function
Decode64(string[])
{
new length, length2, length3;
new block, pad;
length = strlen(string);
for(new x = 0; x < 2; x++)
{
	if(string[length - x - 1] == '=')
		pad++;
}

block = length / 4;
length2 = block * 3;
new buffer[500], buffer2[500], result[500];

for(new x = 0; x < length; x++)
{
	buffer[x] = DecodeMap(string[x]);
}

new b, b1, b2, b3;
new temp1, temp2, temp3, temp4;

for(new x = 0; x < block; x++)
{
	temp1 = buffer[x*4];
	temp2 = buffer[x*4+1];
	temp3 = buffer[x*4+2];
	temp4 = buffer[x*4+3];

	b = (temp1<<2);
	b1 = ((temp2 & 48)>>4);
	b1 += b;

	b = ((temp2 & 15)<<4);
	b2 = ((temp3 & 60)>>2);
	b2 += b;

	b = ((temp3 & 3)<<6);
	b3 = temp4;
	b3 += b;

	buffer2[x*3] = b1;
	buffer2[x*3+1] = b2;
	buffer2[x*3+2] = b3;
}
length3 = length2 - pad;
for(new x = 0; x < length3; x++)
{
	result[x] = buffer2[x];
}
strcpy(output, result);
}

// Returns the position in the encstring
DecodeMap(c)
{
if(c == '=')
	return 0;
else
{
	for(new x = 0; x < 64; x++)
	{
		if(encstring[x] == c)
			return x;
	}
}
}

 

that's what the base64 method looks like non-php.

 

 

Ok, sounds like I decent method. Also thinking of changing the value to letters then as well.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.