[ Log In | Register ]       
» Resource Database Index -> Source Code -> P4Math
Description // Info

Just some math functions that can be used in encryption.
Source Code

  1. /*
  2.  
  3.  
  4. P4Math functions for use in encryption ect...
  5.  
  6. by P4ll4t0n
  7.  
  8. */
  9.  
  10. //-------------------------------------------------------------------------------------
  11. // BEGIN P4MATH.h
  12. //-------------------------------------------------------------------------------------
  13.  
  14. #define P4MAX( a, b ) ( a > b ? a : b )
  15. #define P4MIN( a, b ) ( a < b ? a : b )
  16. #define P4ABS( a ) ( a < 0 ? -1 * a : a )
  17. #define P4FLOOR( a ) ( (int)( a - 0.5) )
  18. #define P4CEIL( a ) ( (int)( a + 0.5 ) )
  19.  
  20. //Gets the Greatest common divisor of a and b
  21. int P4Gcf( long int a, long int b );
  22.  
  23. //Gets the factorial of a number
  24. long int P4Factorial( long int a );
  25.  
  26. //Simple does a exponents only does whole number exponents
  27. long int P4Pow( int n, int e );
  28.  
  29. //Aprox's the sqrt of a number, the > iters is the more acurate the sqrt is
  30. float P4AproxSqrt( float num, int iters );
  31.  
  32. //------END P4Math.h
  33.  
  34. //------------------------------------------------------------------------
  35. // Start P4Math.c
  36. //------------------------------------------------------------------------
  37. #include "./P4Math.h"
  38. int P4Gcf( long int a, long int b )
  39. {
  40.     int max = P4MAX( a, b );
  41.     int min = P4MIN( a, b );
  42.     int remain;
  43.    
  44.     while( min != 0 )
  45.     {
  46.            remain = max % min;
  47.            
  48.            max = min;
  49.            min = remain;
  50.     }
  51.    
  52.     return max;
  53. }
  54.  
  55. long int P4Factorial( long int a )
  56. {
  57.      if( a == 1 || a == -1 )
  58.          return 1;
  59.      
  60.      if( a < 0 )
  61.          return a * P4Factorial( a + 1 );
  62.      
  63.      return a * P4Factorial( a - 1 );
  64. }
  65.  
  66. long int P4Pow( int n, int e )
  67. {
  68.      if( e <= 0 )
  69.          return 1;
  70.          
  71.      if( e == 1 )
  72.          return n;
  73.          
  74.      return n * P4Pow( n, e - 1 );
  75. }
  76.  
  77. float P4AproxSqrt( float num, int iters )
  78. {
  79.       if( num == 0 || num < 0 )
  80.           return 0;
  81.          
  82.       float sqrt, q = num / 2;
  83.      
  84.       for( int i = 0; i < iters; i++ )
  85.       {
  86.            sqrt = ( q + num / q ) / 2;
  87.            
  88.            q = sqrt;
  89.       }
  90.      
  91.       return sqrt;
  92. }


Comments

Add Comment
Please login to leave a comment!


 Network Access...
USER ID
PASSWORD

 Share Exploit
Share






 Code Information
Code Name:
P4Math

Author:
Author Name:
p4ll4t0n
Author's Website:

Author's Email:
[email protected]

Code Details:
Code Version:
Code Submission Date:
Code Submission Time 16:48:42
Submitted By: agri
Language: cpp

Code Ranking: 0 (you must be logged in to rank and vote on source code!)

Tags:


[ Download | Report Issue ]

 Code Search




 

LOL LEGAL STUFF #
By continuing past this page, and by your continued use of this site, you agree to be bound by and abide by the User Agreement.

© 2008-2011 r00tsecurity network. All rights reserved.
About Us | Contact Us | Support Us | Legal | Advertise | Privacy Policy

r00tsecurity's network is powered and running off MeowPower Enterprise Software and is professionally monitored and managed by the Kittens In Suits™.

COMMONLY ACCESSED #
INSPIRE ME #
" That you may retain your self-respect, it is better to displease the people by doing what you know is right, than to temporarily please them by doing what you know is wrong. "
~ William J. H. Boetcker