Jump to content

Simple Obfuscation/Encryption script


jonsjava

Recommended Posts

I wrote this script in a couple minutes yesterday, and converted it into a class today.  My thought process was this:  It would be similar to a public/private key set, in that you send the unix time you used to generate the output with the output, and you both share the salt, so even if someone gets a copy of the encrypted data, the couldn't decrypt the message without the salt.  This is more of a proof-of-concept than anything else.  What I'm wondering: anything you guys/gals can think of to make it more secure?

<?php
class trucrypt{
var $data;
var $salt;
var $date;
var $encrypted;
var $return;
function __construct($data,$salt,$date,$encrypt=true){
	$this->salt = $salt;
	$this->date = $date;
	if ($encrypt == true){
		$this->data = $data;
		$this->crypt();
	}
	else{
		$this->encrypted = $data;
		$this->decrypt();
	}
}
public function crypt(){
	$data = $this->data;
	$salt = $this->salt;
	$date = $this->date;
	$out = array();
	if (!is_numeric($date)){
		$date = date("U",strtotime($date));
	}
	$data_a = str_split($data);
	foreach ($data_a as $key=>$val){
		$out[$key] = md5($val.$salt.$date.$key);
	}
	$this->return = $out;
}
public function decrypt(){
	$encrypted = $this->encrypted;
	$salt = $this->salt;
	$date = $this->date;
	$out = "";
	$charmap = array("\n",0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","!","@","#","$","%","^","&","&","*","(",")","-","_","=","+",";",":","'","\"",",",".","/","\\","|","[","]","{","}","<",">","?","`","~"," ","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
	foreach ($encrypted as $key=>$val){
		foreach ($charmap as $val2){
			$crypt = md5($val2.$salt.$date.$key);
			if ($crypt == $val){
				$out .= $val2;
			}
		}
	}
	$this->return = $out;
}
}
$date = date("U");
//data to be passed, encrypted, and decrypted.
$test = "This is a test
I hope it works!";

$da = new trucrypt($test,"cheeseburger",$date,true);
$encrypted = $da->return;
print_r($encrypted);
echo "\n<br /><br /><br />\n\n\n";
//time to decrypt the message:
$da2 = new trucrypt($encrypted,"cheeseburger",$date,false);
echo $da2->return;
?>

Ok, so a run down of the script: you set the variables, pass it data, and depending on if $encrypt is true or false, it encrypts the data passed, or decrypts it.

Here's some sample output:

 

Array
(
    [0] => d718b48d9c708e5732b587f9c112cf66
    [1] => a18eb70113226b9be861aa679124f219
    [2] => 2caa2890acb53a550fd3ff4aa1306791
    [3] => 837a901e6175328d0a8d881084fac575
    [4] => a8ef4b132a14545a38d53ba8350e5140
    [5] => 612aac95ef685a35c82a9743d36b84d7
    [6] => 5a85abbd16a2eaea1bd6dc90ee57fbbe
    [7] => dd518080918bf9cd60624111caa938e5
    [8] => 11ca44ce2729c27db510b5c4e03cf546
    [9] => a398042d78a833a83e8ad63818bff4fb
    [10] => 8075efeba218fcc53031029f9610d62d
    [11] => b01fae8fb7d0ec516d751b29eb4010a4
    [12] => 49c152494af3fa23df54dc722ee659cf
    [13] => 2724a459ffa0244dbb280f1e7a3c8a2a
    [14] => f665b211ad794d84d29717896b10a3e2
    [15] => 25b39881c5c049b2dec9c857b5229033
    [16] => eff0fed2f132726c299d72db137bb463
    [17] => b14336db3ef38f9e880e60d706c7bf15
    [18] => c1adc49a2c15aadae11ab420a2180a17
    [19] => f0ff9230e732dab839fc2eaa2d88f1b6
    [20] => d0918cf959eb36516d22d6d123e337c5
    [21] => e67f72f41a43024b577515b959dbb4e6
    [22] => b60aa274ef41399237af7d7593b5b78d
    [23] => c5a6a6d9cc729df8c165090b9efd177e
    [24] => b8140ab85cc3182a64101d7ed217b61b
    [25] => 87548b7a2ef981598570b1a3aaad852d
    [26] => 2472a33b4680e057685eef8fe517ee8c
    [27] => eb9bd5b883483c2a0a85d725bd4895fa
    [28] => cecffbfd8a7c872ea89e2c243019f520
    [29] => 38a94dac2d4adb83dee57dd4dbdc4c7c
    [30] => 8ff254c1d988889f04d147e6860be227
    [31] => 6b8260dc4c3dd887d7d5dafafd2abfc9
)

<br /><br /><br />


This is a test
I hope it works!

Link to comment
Share on other sites

×
×
  • 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.