Code Duplication    Length = 20-20 lines in 2 locations

projects/packages/password-checker/src/class-password-checker.php 1 location

@@ 542-561 (lines=20) @@
539
	 *
540
	 * @param String $password the password.
541
	 */
542
	protected function calculate_entropy_bits( $password ) {
543
		$bits          = 0;
544
		$charset_score = log( $this->get_charset_size( $password ) ) / log( 2 );
545
546
		$aidx   = $this->get_char_index( $password[0] );
547
		$length = strlen( $password );
548
549
		for ( $b = 1; $b < $length; $b++ ) {
550
			$bidx = $this->get_char_index( $password[ $b ] );
551
552
			// 27 = number of chars in the index (a-z,' ').
553
			$c     = 1.0 - $this->frequency_table[ $aidx * 27 + $bidx ];
554
			$bits += $charset_score * $c * $c;
555
556
			// Move on to next pair.
557
			$aidx = $bidx;
558
		}
559
560
		return $bits;
561
	}
562
563
	/**
564
	 * A frequency table of character pairs, starting with  '  ' then  ' a', ' b' [...] , 'a ', 'aa' etc.

projects/plugins/jetpack/_inc/lib/class.jetpack-password-checker.php 1 location

@@ 530-549 (lines=20) @@
527
	 *
528
	 * @param String $password the password.
529
	 */
530
	protected function calculate_entropy_bits( $password ) {
531
		$bits          = 0;
532
		$charset_score = log( $this->get_charset_size( $password ) ) / log( 2 );
533
534
		$aidx   = $this->get_char_index( $password[0] );
535
		$length = strlen( $password );
536
537
		for ( $b = 1; $b < $length; $b++ ) {
538
			$bidx = $this->get_char_index( $password[ $b ] );
539
540
			// 27 = number of chars in the index (a-z,' ').
541
			$c     = 1.0 - $this->frequency_table[ $aidx * 27 + $bidx ];
542
			$bits += $charset_score * $c * $c;
543
544
			// Move on to next pair.
545
			$aidx = $bidx;
546
		}
547
548
		return $bits;
549
	}
550
551
	/**
552
	 * A frequency table of character pairs, starting with  '  ' then  ' a', ' b' [...] , 'a ', 'aa' etc.