ellisgl
08-14-2007, 04:45 PM
I know that the windows application is no longer maintained and is now been made into a PEAR Package. Last time I dealt with any code reformatting tool, it would format it one way, or has a small set of extra rules. What I would like to know is has anyone played with the PEAR version and can it take this:
function text_decrypt($s, $key = false) {
global $blowfish;
if (strlen($s) == 0)
return $s;
# Parse crypted data
$type = func_get_crypt_type($s);
if ($type === false) {
$type = "N";
$crc32 = false;
} elseif (substr($s, 1, 1) == '-') {
$crc32 = true;
$s = substr($s, 2);
} else {
$crc32 = substr($s, 1, 8);
$s = substr($s, 9);
}
# Blowfish
if ($type == 'B' || $type == 'C') {
if ($key === false)
$key = func_get_crypt_key($type);
if (!$blowfish) {
x_log_flag("log_decrypt_errors", "DECRYPT", "The Blowfish service object is missing", true);
return false;
} elseif (empty($key)) {
x_log_flag("log_decrypt_errors", "DECRYPT", "The key for the selected type ('".$type."') of encryption is missing", true);
return false;
}
$result = trim(func_bf_decrypt($s, $key));
} elseif ($type == 'N') {
# Non-encrypted
$result = $s;
}
# CRC32 check
if ($crc32 === true) {
# Inner CRC32
$crc32 = substr($result, -8);
$result = substr($result, 0, -8);
if (func_crc32(md5($result)) != $crc32)
$result = NULL;
} elseif ($crc32 !== false) {
# Outer CRC32
if (func_crc32($result) != $crc32)
$result = NULL;
}
return $result;
}
and make it look like this (the way I like to see code styled):
function text_decrypt($s, $key = false)
{
global $blowfish;
if(strlen($s) == 0)
{
return $s;
}
# Parse crypted data
$type = func_get_crypt_type($s);
if($type === false)
{
$type = "N";
$crc32 = false;
}
elseif(substr($s, 1, 1) == '-')
{
$crc32 = true;
$s = substr($s, 2);
}
else
{
$crc32 = substr($s, 1, 8);
$s = substr($s, 9);
}
# Blowfish
if($type == 'B' || $type == 'C')
{
if($key === false)
{
$key = func_get_crypt_key($type);
}
if(!$blowfish)
{
x_log_flag("log_decrypt_errors", "DECRYPT", "The Blowfish service object is missing", true);
return false;
}
elseif(empty($key))
{
x_log_flag("log_decrypt_errors", "DECRYPT", "The key for the selected type ('".$type."') of encryption is missing", true);
return false;
}
$result = trim(func_bf_decrypt($s, $key));
}
elseif($type == 'N')
{
# Non-encrypted
$result = $s;
}
# CRC32 check
if($crc32 === true)
{
# Inner CRC32
$crc32 = substr($result, -8);
$result = substr($result, 0, -8);
if(func_crc32(md5($result)) != $crc32)
{
$result = NULL;
}
}
elseif($crc32 !== false)
{
# Outer CRC32
if(func_crc32($result) != $crc32)
{
$result = NULL;
}
}
return $result;
}
As you can tell I have a couple rules in the way I style code. Of course it doesn't show up fully on here - cut and paste it to your favorite editor..
function text_decrypt($s, $key = false) {
global $blowfish;
if (strlen($s) == 0)
return $s;
# Parse crypted data
$type = func_get_crypt_type($s);
if ($type === false) {
$type = "N";
$crc32 = false;
} elseif (substr($s, 1, 1) == '-') {
$crc32 = true;
$s = substr($s, 2);
} else {
$crc32 = substr($s, 1, 8);
$s = substr($s, 9);
}
# Blowfish
if ($type == 'B' || $type == 'C') {
if ($key === false)
$key = func_get_crypt_key($type);
if (!$blowfish) {
x_log_flag("log_decrypt_errors", "DECRYPT", "The Blowfish service object is missing", true);
return false;
} elseif (empty($key)) {
x_log_flag("log_decrypt_errors", "DECRYPT", "The key for the selected type ('".$type."') of encryption is missing", true);
return false;
}
$result = trim(func_bf_decrypt($s, $key));
} elseif ($type == 'N') {
# Non-encrypted
$result = $s;
}
# CRC32 check
if ($crc32 === true) {
# Inner CRC32
$crc32 = substr($result, -8);
$result = substr($result, 0, -8);
if (func_crc32(md5($result)) != $crc32)
$result = NULL;
} elseif ($crc32 !== false) {
# Outer CRC32
if (func_crc32($result) != $crc32)
$result = NULL;
}
return $result;
}
and make it look like this (the way I like to see code styled):
function text_decrypt($s, $key = false)
{
global $blowfish;
if(strlen($s) == 0)
{
return $s;
}
# Parse crypted data
$type = func_get_crypt_type($s);
if($type === false)
{
$type = "N";
$crc32 = false;
}
elseif(substr($s, 1, 1) == '-')
{
$crc32 = true;
$s = substr($s, 2);
}
else
{
$crc32 = substr($s, 1, 8);
$s = substr($s, 9);
}
# Blowfish
if($type == 'B' || $type == 'C')
{
if($key === false)
{
$key = func_get_crypt_key($type);
}
if(!$blowfish)
{
x_log_flag("log_decrypt_errors", "DECRYPT", "The Blowfish service object is missing", true);
return false;
}
elseif(empty($key))
{
x_log_flag("log_decrypt_errors", "DECRYPT", "The key for the selected type ('".$type."') of encryption is missing", true);
return false;
}
$result = trim(func_bf_decrypt($s, $key));
}
elseif($type == 'N')
{
# Non-encrypted
$result = $s;
}
# CRC32 check
if($crc32 === true)
{
# Inner CRC32
$crc32 = substr($result, -8);
$result = substr($result, 0, -8);
if(func_crc32(md5($result)) != $crc32)
{
$result = NULL;
}
}
elseif($crc32 !== false)
{
# Outer CRC32
if(func_crc32($result) != $crc32)
{
$result = NULL;
}
}
return $result;
}
As you can tell I have a couple rules in the way I style code. Of course it doesn't show up fully on here - cut and paste it to your favorite editor..