Encryption in PHP without extensions

 
Post new topic   Reply to topic    Aprelium Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Fri Aug 25, 2006 10:57 pm    Post subject: Encryption in PHP without extensions Reply with quote

I was pretty bored in school today, so I decided to write two functions in PHP which can be used to both encrypt and decrypt text using MD5. The encryption is pretty fast and takes a lot of space. The decryption is pretty slow, though very secure.

I do not recommend you to use it with big files or big text documents. I use it in my stand-alone PHP-applications when I need to connect to my server from an unsecure connection and transfer some data.

Feel free to use it however you want.

Code:
<?php
set_time_limit(600);
error_reporting(0);
function encrypt($__content, $__key) {
   $__content = chunk_split(base64_encode($__content), 1, ",");
   $__content = explode(",", $__content);
   foreach($__content as $void => $__row) {
      $__cache_content = $__cache_content.md5($__row.rand(1, 5).$__key).",";
   }
   return $__cache_content;
}

function decrypt($__content, $__key) {
   $__content = explode(",", $__content);
   $__possible_chars = "1234567890=QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
   $__possible_chars = explode(",", chunk_split($__possible_chars, 1, ","));
   foreach($__content as $void => $__row) {
      foreach ($__possible_chars as $void2 => $__row_char) {
         for($i=1;$i!=6;$i++) {
            if (md5($__row_char.$i.$__key) == $__row) {
               $__cache_res = $__cache_res.$__row_char;
            }
         }
      }
   }
   return base64_decode($__cache_res);
}
?>



Quote:

key = 1337
853731acff43bd85becfb2ccdfc6278f,c122dbfd2520745f54d7fa94525dfbb7,3901a63387b7e000b0e9fb98ad1c0463,3b2439cfd534f0a6931f0e9bad6eb427,bc6e1826a881c674f2400c75e79bdfbb


Last edited by cmxflash on Mon Aug 28, 2006 10:48 pm; edited 2 times in total
Back to top View user's profile Send private message
Tom Chapman
-


Joined: 09 Jul 2005
Posts: 933
Location: Australia

PostPosted: Sat Aug 26, 2006 1:57 pm    Post subject: Reply with quote

Soooo how do I use it? :P
Back to top View user's profile Send private message Visit poster's website MSN Messenger
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Sat Aug 26, 2006 2:00 pm    Post subject: Reply with quote

MrWiseOne wrote:
Soooo how do I use it? :P


To encrypt:
Code:
<?php
include("encryption.php"); //Or whatever you pasted the code into
echo encrypt("some data to encrypt", "the secret key"); //Will generate one shitloada text
?>


To decrypt:
Code:
<?php
include("encryption.php"); //Or whatever you pasted the code into
echo decrypt("The encrypted text here", "the secret key");
?>
Back to top View user's profile Send private message
Tom Chapman
-


Joined: 09 Jul 2005
Posts: 933
Location: Australia

PostPosted: Sat Aug 26, 2006 2:03 pm    Post subject: Reply with quote

Awesome work CMX. :)
Back to top View user's profile Send private message Visit poster's website MSN Messenger
Mikor
-


Joined: 21 Aug 2006
Posts: 144
Location: Hull, England

PostPosted: Sat Aug 26, 2006 2:08 pm    Post subject: Reply with quote

Sooo... the decrypt function is basicly a brute-force attempt at guessing the original data?
_________________
Yarrt.com - Free Arcade
RypNet.co.uk - Online Game

MSN:
michael_walker_2004 <at> hotmail <dot> com
Back to top View user's profile Send private message Send e-mail MSN Messenger
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Sat Aug 26, 2006 2:27 pm    Post subject: Reply with quote

Mikor wrote:
Sooo... the decrypt function is basicly a brute-force attempt at guessing the original data?


Well, MD5 is a one-way hash encryption. If you suggest another way of recovering the data, feel free to post it here.


Last edited by cmxflash on Mon Aug 28, 2006 10:46 pm; edited 1 time in total
Back to top View user's profile Send private message
Tom Chapman
-


Joined: 09 Jul 2005
Posts: 933
Location: Australia

PostPosted: Sat Aug 26, 2006 2:31 pm    Post subject: Reply with quote

Now why didn't I ask that!
Back to top View user's profile Send private message Visit poster's website MSN Messenger
Mikor
-


Joined: 21 Aug 2006
Posts: 144
Location: Hull, England

PostPosted: Sat Aug 26, 2006 3:19 pm    Post subject: Reply with quote

cmxflash wrote:
Mikor wrote:
Sooo... the decrypt function is basicly a brute-force attempt at guessing the original data?


Well, MD5 is a one-way hash encryption. If you suggest another way of revovering the data, feel free to post it here.


Why not use another method of data encryption?
ie: multiple base64_encode's or something.

I'm making an encrypt/decrypt function now, it lets the owner of the script customize the encryption by editing an array which contains the order for running functions
ie: the array could be ('rot13','salt','base64','rot13')

Its pretty good, for example, if you input the string "test" with the encryption ('base64','rot13','salt','salt2','reverse','rot13','base64'), it will output: cDgxNDFyc25uczk2NTE5NW40N28ycTQyNW8wbm8zbzluNG9xMTg5NzAwMDExMTEwMTExMDEwMDExMTAxMT09QWR6VkdkMDAwMTExMTAxMTEwMTAwMTExMDExcHIwNXAzcjg3bjZxcnM1NjhybzBuOHIwcHE1NjE4OTc=
_________________
Yarrt.com - Free Arcade
RypNet.co.uk - Online Game

MSN:
michael_walker_2004 <at> hotmail <dot> com
Back to top View user's profile Send private message Send e-mail MSN Messenger
Tom Chapman
-


Joined: 09 Jul 2005
Posts: 933
Location: Australia

PostPosted: Sat Aug 26, 2006 3:56 pm    Post subject: Reply with quote

Dumb-Ass-Tom-Time! lol

So are you saying that your script will encrypt a string into all those?
Back to top View user's profile Send private message Visit poster's website MSN Messenger
Mikor
-


Joined: 21 Aug 2006
Posts: 144
Location: Hull, England

PostPosted: Sat Aug 26, 2006 4:19 pm    Post subject: Reply with quote

No, it loops through that array,

eg:
if its ('reverse','base64','rot13')
it will reverse the string, base64_encode it, and then str_rot13 it.
_________________
Yarrt.com - Free Arcade
RypNet.co.uk - Online Game

MSN:
michael_walker_2004 <at> hotmail <dot> com
Back to top View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Tutorials All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group