<?php
/*
Bren2010 Encryption/Decryption Algorithms v. 1.0
Developer: Brendan M.
Website: http://www.bren2010.com/
Date: November 22, 2009
*/

// Encryption Function
function EBCrypt($message, $password) {
// Define Variables
$messa = str_split($message);
$passa = str_split($password);

$encrypted = array();
$p = 0;
$pc = count($passa) - 1;

// Begin Encryption
foreach ($messa as $char) {
// Define Variables
$pchar = $passa["$p"];

$cascii = ord($char);
$pascii = ord($pchar);

// Begin Minipulation
$prenc = $cascii + $pascii;
$rand = rand (1, 30);
$step1 = ($cascii + $pascii) / 2;
$step2 = round($step1) - $rand;

$step3 = $prenc - $step2;

// Push into array
array_push($encrypted, $step2, $step3);

// Tell if the password needs to be looped
if ($p == $pc) {
$p = 0;
} else {
$p++;

}
}
// Return encrypted string
$finish = implode(".", $encrypted);
return $finish;
}
// Decryption Function
function DBCrypt($message, $password) {

// Define Variables
$messa = explode(".", $message);
$passa = str_split($password);
$decrypted = array();
$m = 0;
$p = 0;
$mc = count($messa) - 1;
$pc = count($passa) - 1;

// Begin Decryption
while ($m <= $mc) {
// Define variables
$char1 = $messa["$m"];
$tm = $m+1;
$char2 = $messa["$tm"];
$pchar = ord($passa["$p"]);

// Begin Minipulation

$step1 = $char1 + $char2;
$step2 = $step1 - $pchar;
$step3 = chr($step2);

// Push into array
array_push($decrypted, $step3);

// Refresh variables
$m++;
$m++;

// Tell if the password needs to be looped

if ($p == $pc) {
$p = 0;
} else {
$p++;
}
}
// Return string

$finish = implode($decrypted);
return $finish;
}
?>