Code Duplication    Length = 20-20 lines in 2 locations

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.

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

@@ 552-571 (lines=20) @@
549
	 *
550
	 * @return float|int
551
	 */
552
	protected function calculate_entropy_bits( $password ) {
553
		$bits = 0;
554
		// Calculate the score.
555
		$charset_score = log( $this->get_charset_size( $password ) ) / log( 2 );
556
557
		$aidx   = $this->get_char_index( $password[0] );
558
		$length = strlen( $password );
559
560
		for ( $b = 1; $b < $length; $b ++ ) {
561
			$bidx = $this->get_char_index( $password[ $b ] );
562
563
			// 27 = number of chars in the index (a-z,' ').
564
			$c = 1.0 - $this->frequency_table[ $aidx * 27 + $bidx ];
565
566
			// Increment the bits.
567
			$bits += $charset_score * $c * $c;
568
569
			// Move on to next pair.
570
			$aidx = $bidx;
571
		}
572
573
		return $bits;
574
	}