English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Can someone help me finding some good encode and decode / encryption and decryption methods for strings in php which doesn't put special characters in the result string when encoded.

Example:
$str = "this is a string";
$something = encode($str);
echo $something;
a82hliha8sdf7p9829189jsjfsdf //no special characters

but i do need the decrypt of decode or decryption function associated to its encrypt function.

I don't need the one way hash functions like md5.

Thankyou.

2006-09-12 23:21:46 · 5 answers · asked by Manish 5 in Computers & Internet Programming & Design

5 answers

Read up on the mcrypt functions in PHP. You'll need to make sure that mcrypt is compiled into the PHP distribution you're using:
http://www.php.net/manual/en/function.mcrypt-encrypt.php

Basically you can do stuff like this:
// The "iv" stuff is for the "initialization vector." See the page for more details.
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key = "This is a very secret key";
$text = "Meet me at 11 o'clock behind the monument.";
$secrettext = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv));
// base64 makes sure there are no special characters!

Now $secrettext is your code!
To decode, you just do it backwards:
// The "iv" stuff is for the "initialization vector." See the page for more details.
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key = "This is a very secret key";
$plaintext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($text), MCRYPT_MODE_ECB, $iv));

And there you have it! You can do all sorts of crazy cryptographic functions using this!

2006-09-12 23:34:24 · answer #1 · answered by std 3 · 0 0

Well the easiest way would be a simple Ceaser cypher where you replace each character with another so say a becomes d, f becomes j and so on. This is easy to do using an array. You can reverse it using the same method. it's all a question of how obscure you want to make the encrypted string.

You could also lok at the ord() and chr() functions as a way of encrypting it. A combination of these two methods would produce a good method.

2006-09-12 23:34:25 · answer #2 · answered by carbonize 3 · 0 1

Generally, you should expect some special characters in your encrypted data. There is a way to get around it, however. Use any encryption algorithm you want, but when you get the encrypted data, transform it and convert each byte into its two-byte hexadecimal presentation. Say, you have a linefeed symbol (ASCII 10); replace it with a two-symbol sequence 0A. Decrypting will then work in reverse; first, break the data into two-byte segments, convert each into a character (say, 5A becomes Z), then, decrypt.

2006-09-14 05:12:05 · answer #3 · answered by NC 7 · 0 0

your pic looks like ringo starr out of the beatles lol

2006-09-12 23:33:11 · answer #4 · answered by Anonymous · 0 0

go to www.download.com you will find many softwares.

2006-09-12 23:29:36 · answer #5 · answered by Anonymous · 0 1

fedest.com, questions and answers