[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorHashTestCase extends PhabricatorTestCase { 4 5 public function testHashForIndex() { 6 $map = array( 7 'dog' => 'Aliif7Qjd5ct', 8 'cat' => 'toudDsue3Uv8', 9 'rat' => 'RswaKgTjqOuj', 10 'bat' => 'rAkJKyX4YdYm', 11 ); 12 13 foreach ($map as $input => $expect) { 14 $this->assertEqual( 15 $expect, 16 PhabricatorHash::digestForIndex($input), 17 "Input: {$input}"); 18 } 19 20 // Test that the encoding produces 6 bits of entropy per byte. 21 $entropy = array( 22 'dog', 'cat', 'rat', 'bat', 'dig', 'fig', 'cot', 23 'cut', 'fog', 'rig', 'rug', 'dug', 'mat', 'pat', 24 'eat', 'tar', 'pot', 25 ); 26 27 $seen = array(); 28 foreach ($entropy as $input) { 29 $chars = preg_split('//', PhabricatorHash::digestForIndex($input)); 30 foreach ($chars as $char) { 31 $seen[$char] = true; 32 } 33 } 34 35 $this->assertEqual( 36 (1 << 6), 37 count($seen), 38 "Distinct characters in hash of: {$input}"); 39 } 40 41 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |