mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
Merge branch 'split-file_simplecrypt.class.inc.php_SimpleCryptSimpleEngine.php' into split-file_simplecrypt.class.inc.php
This commit is contained in:
38
sources/Application/SimpleCrypt/SimpleCryptSimpleEngine.php
Normal file
38
sources/Application/SimpleCrypt/SimpleCryptSimpleEngine.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Simple Engine doesn't need any PHP extension.
|
||||
* Every encryption of the same string with the same key
|
||||
* will return the same encrypted string
|
||||
*/
|
||||
class SimpleCryptSimpleEngine implements CryptEngine
|
||||
{
|
||||
public static function GetNewDefaultParams()
|
||||
{
|
||||
return array('lib' => 'Simple', 'key' => null);
|
||||
}
|
||||
|
||||
public function Encrypt($key, $sString)
|
||||
{
|
||||
$result = '';
|
||||
for ($i = 1; $i <= strlen($sString); $i++) {
|
||||
$char = substr($sString, $i - 1, 1);
|
||||
$keychar = substr($key, ($i % strlen($key)) - 1, 1);
|
||||
$char = chr(ord($char) + ord($keychar));
|
||||
$result .= $char;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function Decrypt($key, $encrypted_data)
|
||||
{
|
||||
$result = '';
|
||||
for ($i = 1; $i <= strlen($encrypted_data); $i++) {
|
||||
$char = substr($encrypted_data, $i - 1, 1);
|
||||
$keychar = substr($key, ($i % strlen($key)) - 1, 1);
|
||||
$char = chr(ord($char) - ord($keychar));
|
||||
$result .= $char;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user