Permalink
Browse files

Optimized Security::cipher(). Fixes #176

Signed-off-by: Mark Story <mark@mark-story.com>
  • Loading branch information...
1 parent 1cfd273 commit ad496cea181323b21526b495bfa513119678ec0f @jrbasso jrbasso committed with markstory Jan 11, 2010
Showing with 6 additions and 4 deletions.
  1. +6 −4 cake/libs/security.php
View
@@ -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();

0 comments on commit ad496ce

Please sign in to comment.