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

@@ 554-573 (lines=20) @@
551
	 *
552
	 * @param String $password the password.
553
	 */
554
	protected function calculate_entropy_bits( $password ) {
555
		$bits          = 0;
556
		$charset_score = log( $this->get_charset_size( $password ) ) / log( 2 );
557
558
		$aidx   = $this->get_char_index( $password[0] );
559
		$length = strlen( $password );
560
561
		for ( $b = 1; $b < $length; $b++ ) {
562
			$bidx = $this->get_char_index( $password[ $b ] );
563
564
			// 27 = number of chars in the index (a-z,' ').
565
			$c     = 1.0 - $this->frequency_table[ $aidx * 27 + $bidx ];
566
			$bits += $charset_score * $c * $c;
567
568
			// Move on to next pair.
569
			$aidx = $bidx;
570
		}
571
572
		return $bits;
573
	}
574
575
	/**
576
	 * A frequency table of character pairs, starting with  '  ' then  ' a', ' b' [...] , 'a ', 'aa' etc.