Skip to content

Commit

Permalink
Optimized Security::cipher(). Fixes #176
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Story <mark@mark-story.com>
  • Loading branch information
jrbasso authored and markstory committed Jan 22, 2010
1 parent 1cfd273 commit ad496ce
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cake/libs/security.php
Expand Up @@ -177,12 +177,14 @@ function cipher($text, $key) {
srand(Configure::read('Security.cipherSeed'));
$out = '';

for ($i = 0; $i < strlen($text); $i++) {
for ($j = 0; $j < ord(substr($key, $i % strlen($key), 1)); $j++) {
$toss = rand(0, 255);
$keyLength = strlen($key);
for ($i = 0, $j = strlen($text); $i < $j; $i++) {
$k = ord($key[$i % $keyLength]);
while ($k-- > 0) {
rand(0, 255);
}
$mask = rand(0, 255);
$out .= chr(ord(substr($text, $i, 1)) ^ $mask);
$out .= chr(ord($text[$i]) ^ $mask);
}

srand();
Expand Down

0 comments on commit ad496ce

Please sign in to comment.