Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use POSIX qw/floor/;
- use bignum ;
- #########################################################
- # Written by blackbox/motherbrain #
- # Think outside the box :) #
- # #
- # This is for people interested in #
- # hashing algorithms #
- # SHA algorithms are a little bit #
- # Better the md5 my eyes #
- # At least the 512bit one :) #
- # Under the NFPL license #
- # #
- #########################################################
- # function that takes a number and return true if it is prime
- # false other wise
- sub isPrime
- {
- if( $_[0] == 2 )
- {
- return true ;
- }
- for ( $k=2 ; $k < $_[0] ; $k++ )
- {
- if( ($_[0] % $k) == 0 )
- {
- return false ;
- }
- }
- return true ;
- }
- #Gets the first N primes
- sub getPrimes
- {
- $N=$_[0] ;
- $i=0;
- $j=2;
- @primes ;
- while ( $i < $N )
- {
- if( (isPrime $j ) eq true ) {
- push( @primes , "$j") ;
- $i++;
- }
- $j++;
- }
- return @primes ;
- }
- #function for displaying the N primes
- sub printPrimes
- {
- @p = @_ ;
- for( $i=0 ; $i < ($#p + 1) ; $i++ )
- {
- if( $i == $#p )
- {
- print "@p[$i]" ;
- return ;
- }
- print "@p[$i] ," ;
- }
- }
- sub cuberoots
- {
- @p = @_ ;
- for( $i = 0 ; $i < 64 ; $i++ )
- {
- $tmp = Math::BigFloat->new(@p[$i] ) ;
- $tmp = $tmp->broot(3) ;
- @p[$i] = $tmp ;
- }
- return @p ;
- }
- sub frac2hex
- {
- $num = $_[0] ;
- $N = $_[1] ;
- $t = rindex($num , ".") ;
- $num = substr( $num , $t ) ;
- $const = Math::BigFloat->new(2) ;
- $const = $const->bpow($N) ;
- $BNUM = Math::BigFloat->new($num) ;
- $tmp = $BNUM->bmul($const) ;
- $tmp = $tmp->bfloor($tmp) ;
- $tmp2 = Math::BigInt->new($tmp) ;
- $hex = $tmp2->as_hex() ;
- return $hex ;
- }
- sub arrayfrac2hex
- {
- @s = @_ ;
- for( $i=0 ; $i< ($#s + 1) ; $i++ )
- {
- @s[$i] = frac2hex( @s[$i] , ($#s + 1) ) ;
- }
- return @s ;
- }
- Math::BigFloat->precision(70); # Precision
- Math::BigFloat->accuracy(70); # Accuracy
- print "SHA Constant calculator \n" ;
- @pn = getPrimes(64) ; # change the value to 64 , 80 or whatever many primes to get :)
- print "Please wait may take sometime...\n" ;
- @c = cuberoots @pn ;
- print "\nPrimes are \n" ;
- printPrimes @pn;
- print "\nCubic roots of those primes are \n" ;
- print @c ;
- print "\nHex values for the fractional parts of the cubic roots of primes\nSHA constants for 384, 512 :) \n " ;
- @w = arrayfrac2hex @c ;
- print "@w " ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement