Jump to content

[SOLVED] Simple Encryption/Decryption?


Michdd

Recommended Posts

it really depends on you.

 

i mean if you really wanted you could do something simple like assign a=1 b=2 ect

 

then count the string length  add that onto each number

and then change the string to the numbers.

 

decrypt it by reversing lol

Think if encryption as a function, and think of decrypting as the inverse of said function.

 

 

For example, if f(1) = 3, then f^-1(3) should = 1.  (f^-1 meaning opposite of f.)

 

 

 

So, you'll essentially need to come up with something that can be reversed, but not done so easily.  You could use a key to encrypt it against, or you could just change the value or what ever.

 

 

 

Or, you could use some of the algorithms already out there.

it really depends on you.

 

i mean if you really wanted you could do something simple like assign a=1 b=2 ect

 

then count the string length  add that onto each number

and then change the string to the numbers.

 

decrypt it by reversing lol

 

How could I make something that would change all, for example, a's to 3, within a certain string?

it really depends on you.

 

i mean if you really wanted you could do something simple like assign a=1 b=2 ect

 

then count the string length  add that onto each number

and then change the string to the numbers.

 

decrypt it by reversing lol

 

How could I make something that would change all, for example, a's to 3, within a certain string?

 

regex

Horrid ideas. >_>  Just use simple XOR encryption.  I wrote up a quick set of functions for you:

 

<?php
function xor_crypt($input, $key) {
$input_l = strlen($input);
$key_l = strlen($key);
for ($i=0;$i<$input_l;$i++) {
	$pos = $i % $key_l;
	$input[$i] = chr(ord($input[$i]) ^ ord($key[$pos]));
}
return $input;
}

function do_encrypt($input, $key) {
$input = xor_crypt($input, $key);
$input = base64_encode($input);
return $input;
}

function do_decrypt($input, $key) {
$input = base64_decode($input);
$input = xor_crypt($input, $key);
return $input;
}

 

Usage:

<?php
$string = "JUST some RANDOM string going on here.... >_>";
$key = "ASHD77278qu389*A*S*D0a)))(ASdjuio!$^$RHF";
$enc = do_encrypt($string, $key);
echo "$enc\n";
echo do_decrypt($enc, $key) . "\n";

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.