[OWASP_PHPSEC] Code not able to understand

rahul chaudhary rahul300chaudhary400 at gmail.com
Thu May 30 03:29:12 UTC 2013


Abbas,
The following code from jframework is to find ordered characters in a given
string.

private static function hasOrderedCharacters($string, $length) {
$length=(int)$length;
$i = 0;
$j = strlen($string);
$str = implode('', array_map(function($m) use (&$i, &$j) {
return chr((ord($m[0]) + $j--) % 256) . chr((ord($m[0]) + $i++) % 256);
}, str_split($string, 1)));
return preg_match('#(.)(.\1){' . ($length - 1) . '}#', $str)==true;
}


In this code I am not able to understand this line:
return chr((ord($m[0]) + $j--) % 256) . chr((ord($m[0]) + $i++) % 256);

In the code I do understand what it is doing, the regular expression and
all that...but why are you doing this...for what reason you are adding and
subtracting I cannot understand.
-- 
Regards,
Rahul Chaudhary
Ph - 412-519-9634
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.owasp.org/pipermail/owasp_php_security_project/attachments/20130529/63f4cffb/attachment.html>


More information about the OWASP_PHP_Security_Project mailing list