Advertisement
Guest User

Untitled

a guest
Jan 10th, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use POSIX qw/floor/;
  4. use bignum ;
  5.  
  6. #########################################################
  7. # Written by blackbox/motherbrain #
  8. # Think outside the box :) #
  9. # #
  10. # This is for people interested in #
  11. # hashing algorithms #
  12. # SHA algorithms are a little bit #
  13. # Better the md5 my eyes #
  14. # At least the 512bit one :) #
  15. # Under the NFPL license #
  16. # #
  17. #########################################################
  18.  
  19.  
  20. # function that takes a number and return true if it is prime
  21. # false other wise
  22. sub isPrime
  23. {
  24.  
  25. if( $_[0] == 2 )
  26. {
  27. return true ;
  28. }
  29.  
  30. for ( $k=2 ; $k < $_[0] ; $k++ )
  31. {
  32.  
  33. if( ($_[0] % $k) == 0 )
  34. {
  35.  
  36. return false ;
  37. }
  38.  
  39. }
  40.  
  41. return true ;
  42. }
  43.  
  44. #Gets the first N primes
  45. sub getPrimes
  46. {
  47. $N=$_[0] ;
  48. $i=0;
  49. $j=2;
  50. @primes ;
  51.  
  52. while ( $i < $N )
  53. {
  54.  
  55. if( (isPrime $j ) eq true ) {
  56. push( @primes , "$j") ;
  57. $i++;
  58. }
  59. $j++;
  60. }
  61.  
  62. return @primes ;
  63. }
  64.  
  65. #function for displaying the N primes
  66. sub printPrimes
  67. {
  68. @p = @_ ;
  69. for( $i=0 ; $i < ($#p + 1) ; $i++ )
  70. {
  71. if( $i == $#p )
  72. {
  73. print "@p[$i]" ;
  74. return ;
  75. }
  76. print "@p[$i] ," ;
  77.  
  78. }
  79.  
  80. }
  81.  
  82. sub cuberoots
  83. {
  84.  
  85. @p = @_ ;
  86. for( $i = 0 ; $i < 64 ; $i++ )
  87. {
  88.  
  89. $tmp = Math::BigFloat->new(@p[$i] ) ;
  90.  
  91. $tmp = $tmp->broot(3) ;
  92. @p[$i] = $tmp ;
  93.  
  94. }
  95.  
  96. return @p ;
  97.  
  98. }
  99.  
  100. sub frac2hex
  101. {
  102. $num = $_[0] ;
  103. $N = $_[1] ;
  104. $t = rindex($num , ".") ;
  105. $num = substr( $num , $t ) ;
  106. $const = Math::BigFloat->new(2) ;
  107. $const = $const->bpow($N) ;
  108. $BNUM = Math::BigFloat->new($num) ;
  109. $tmp = $BNUM->bmul($const) ;
  110. $tmp = $tmp->bfloor($tmp) ;
  111. $tmp2 = Math::BigInt->new($tmp) ;
  112. $hex = $tmp2->as_hex() ;
  113.  
  114. return $hex ;
  115.  
  116. }
  117.  
  118. sub arrayfrac2hex
  119. {
  120. @s = @_ ;
  121. for( $i=0 ; $i< ($#s + 1) ; $i++ )
  122. {
  123. @s[$i] = frac2hex( @s[$i] , ($#s + 1) ) ;
  124. }
  125.  
  126. return @s ;
  127. }
  128.  
  129. Math::BigFloat->precision(70); # Precision
  130. Math::BigFloat->accuracy(70); # Accuracy
  131.  
  132. print "SHA Constant calculator \n" ;
  133. @pn = getPrimes(64) ; # change the value to 64 , 80 or whatever many primes to get :)
  134. print "Please wait may take sometime...\n" ;
  135. @c = cuberoots @pn ;
  136.  
  137. print "\nPrimes are \n" ;
  138. printPrimes @pn;
  139.  
  140. print "\nCubic roots of those primes are \n" ;
  141. print @c ;
  142.  
  143. print "\nHex values for the fractional parts of the cubic roots of primes\nSHA constants for 384, 512 :) \n " ;
  144. @w = arrayfrac2hex @c ;
  145. print "@w " ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement