[OWASP_PHPSEC] Code not able to understand

Abbas Naderi abiusx at owasp.org
Thu May 30 11:12:26 UTC 2013


Because we are checking for both
123456 as a sequence as well as 654321
-Abbas
On ۹ خرداد ۱۳۹۲, at ۷:۵۹, rahul chaudhary <rahul300chaudhary400 at gmail.com> wrote:

> 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
> _______________________________________________
> OWASP_PHP_Security_Project mailing list
> OWASP_PHP_Security_Project at lists.owasp.org
> https://lists.owasp.org/mailman/listinfo/owasp_php_security_project



More information about the OWASP_PHP_Security_Project mailing list