Scripts

G-I Crypt

Deze class encrypt data door middel van een password het werkt op een binaire niveau. Hier beneden geef ik een voorbeeld hoe de raw versie werkt. ******************************************************************************************************* * The first part gathering information. * * * * Message = Hello Password=Test * * * * Message binary = (H) 0100 1000 | (e) 0110 0101 | (l) 0110 1100 | (l) 0110 1100 | (o) 0110 1111 * * * * Password binary = (T) 0101 0100 | (e) 0110 0101 | (s) 0111 0011 | (t) 0111 0100 | * * * *-----------------------------------------------------------------------------------------------------* * Here we are going to encrypt. * * * * In this part we are going to mix the password with the original data. * * * * (H) 0100 1000 | (e) 0110 0101 | (l) 0110 1100 | (l) 0110 1100 | (o) 0110 1111 (original data) * * (T) 0101 0100 | (e) 0110 0101 | (s) 0111 0011 | (t) 0111 0100 | (T) 0101 0100 (Encryption by pass)* * ----------------------------------------------------------------------------- * * (?) 0001 1100 | (?) 0000 0000 | (?) 0001 1111 | (?) 0001 1000 | (?) 0011 1011 (Output) * * * ******************************************************************************************************* Deze class is nog echter raw, de bedoeling is dat je deze class zelf aanpast zodat je een unieke encryptie krijgt. Je kan natuurlijk alles naar je eigen smaak invullen, je kan heel simpel strev() gebruiken of zelfs een wiskundige methode eromheen bouwen van hoe hij de password toepast(daarbij zou je kunnen denken dat hij op een bepaalde manier de password shuffeld). Ik kan je aanraden als je een eigen methode bedenkt dat je die voor jezelf moet houden, zodat je ook echt een eigen methode hebt. Als er dingen onduidelijk zijn hoor ik ze wel ;). This script is brought to you by G-Interfaces(mijn toekomstige bedrijf). P.S. Als je deze script wilt gebruiken voor php4 moet je de visibility keywords weghalen en de keyword self veranderen in de naam van de class.

gi-crypt
<?php

class g_i_crypt
{


##################These are tools##################


//correct the octet
protected function fixoctet($bin){

	//if you dont put this value first in a var a error wil occur
	$len = (8 - strlen($bin));

	for($i = 0; $i < $len ; $i++){
	
		$bin = "0".$bin; 
	}
	

	return $bin;
}


//makes the key binary
protected function key2octet($key){


	for($o = 0; $o < $this->key_len; $o++){
	
		
		$key_temp = decbin(ord($key[$o]));
		$this->bin_key[$o] = self::fixoctet($key_temp);

	}
	
}


//makes the data binary
protected function data2octet($data){


	for($o = 0; $o < $this->data_len; $o++){
	
		
		$data_temp = decbin(ord($data[$o]));
		$this->bin_data[$o] = self::fixoctet($data_temp);
		

	}
	
}

//converts the binary data to readable
protected function octet2data($data){


	$this->output_data = "";
	
	while(list($key,$value) = each($data)){
		$this->output_data .= chr(bindec($value));
	}
	
}


//blends the two octets together
protected function blendoctet($octet1,$octet2){

	
	for($i = 0; $i < sizeof($octet1); $i++){
		
		$key_pos = $i % sizeof($this->bin_key);
		
		for($o = 0; $o < 8; $o++){
		
			if($octet2[$key_pos][$o] == "1" && $octet1[$i][$o] == "0"){
				$octet1[$i][$o] = "1";
				continue;
			}
			
			if($octet2[$key_pos][$o] == "1" && $octet1[$i][$o] == "1"){
				$octet1[$i][$o] = "0";
				continue;
			}
			
			if($octet2[$key_pos][$o] == "0" && $octet1[$i][$o] == "0"){
				$octet1[$i][$o] = "0";
				continue;
			}
			
			if($octet2[$key_pos][$o] == "0" && $octet1[$i][$o] == "1"){
				$octet1[$i][$o] = "1";
				continue;
			}
		}
	}
	
	$this->output_data = $octet1;
}


##################This is where its about##################


//encrypt the data
public function encrypt($data,$key){

	//data length
	$this->data_len = strlen($data);
	
	//key length
	$this->key_len = strlen($key);
	
	
	//makes the key binary
	self::key2octet($key);
	
	//makes the data binary
	self::data2octet($data);
	
	//blends the password with the data
	self::blendoctet($this->bin_data,$this->bin_key);
	
	//converts the binary data to readable data
	self::octet2data($this->output_data);
	
	//Hmm wondering what this does :P
	return $this->output_data;
	
}


//decrypt the data
public function decrypt($data,$key){

	return self::encrypt($data,$key);
	
}



//end of class
}

$class = new g_i_crypt();
$data = $class->encrypt("G-Interfaces.com","chessere");
echo $data."<br/>";
$data = $class->decrypt($data,"chessere");
echo $data."<br/>";

?>

Reacties

0
Nog geen reacties.