⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 securityimei.c

📁 free sources for gsm
💻 C
字号:

#include "math.h"
#include "..\fl\ffsport.h"

#include "..\system\trident\armreg.h"



/*#include <stdio.h>
#include <string.h>


#include <conio.h>
#include <time.h>
#include <memory.h>
*/
/* 
total 200 small prime numbers
reference web page - http://www.utm.edu/research/primes/lists/small/1000.txt 
*/

#define MAX_PRIME_NUMBERS 150

//extern UINT8 check_buff[60];

const unsigned long PrimeNumbers[MAX_PRIME_NUMBERS] =
{
      2,      3,      5,      7,     11,     13,     17,     19,     23,     29, 
     31,     37,     41,     43,     47,     53,     59,     61,     67,     71, 
     73,     79,     83,     89,     97,    101,    103,    107,    109,    113, 
    127,    131,    137,    139,    149,    151,    157,    163,    167,    173, 
    179,    181,    191,    193,    197,    199,    211,    223,    227,    229, 
    233,    239,    241,    251,    257,    263,    269,    271,    277,    281, 
    283,    293,    307,    311,    313,    317,    331,    337,    347,    349, 
    353,    359,    367,    373,    379,    383,    389,    397,    401,    409, 
    419,    421,    431,    433,    439,    443,    449,    457,    461,    463, 
    467,    479,    487,    491,    499,    503,    509,    521,    523,    541, 
    547,    557,    563,    569,    571,    577,    587,    593,    599,    601, 
    607,    613,    617,    619,    631,    641,    643,    647,    653,    659, 
    661,    673,    677,    683,    691,    701,    709,    719,    727,    733, 
    739,    743,    751,    757,    761,    769,    773,    787,    797,    809, 
    811,    821,    823,    827,    829,    839,    853,    857,    859,    863 
};


unsigned long GCD( unsigned long , unsigned long );
unsigned long tofindE( unsigned long , unsigned long , unsigned long );
unsigned long Round( double j1 );
unsigned long extend( unsigned long , unsigned long );
unsigned long Decrypt( unsigned long , unsigned long , unsigned long );
unsigned long Encrypt( unsigned long , unsigned long , unsigned long );
void Encrypt_Number( char *, char *);
int instr( char *, char , int );
void STRCPY( char *, char *, int, int, int );
void Get_Number(char *, char *);
int Check_Code( unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long );




void Get_Number( char *Enc_Num, char *Ak)
{
	
   unsigned long My_P, My_Q;
   unsigned long P1;
   unsigned long Q1;
   unsigned long PI;
   unsigned long E1;
   unsigned long N1;
   unsigned long M1;
   unsigned long D1;
   char temp[60], i=0 ;

   unsigned long seconds = 0x80000000;
   do
      {
         READ_REG_VALUE( seconds, 0xE000C008 ); 
      }
      while ( seconds & 0x80000000 );
      seconds = seconds & 0x1fffffff;
      seconds = seconds % 86400L;

   

	srand(seconds);
	
	My_P = rand() % ( MAX_PRIME_NUMBERS - 1 );
	srand();
   
   do
      {
			do
			{	
		      My_Q = rand() % ( MAX_PRIME_NUMBERS - 1 );		
			} while( My_P == My_Q );


		   P1 = PrimeNumbers[My_P];
		   Q1 = PrimeNumbers[My_Q];
		   PI = ( P1 - 1 ) * ( Q1 - 1 );
		   E1 = tofindE( PI, P1, Q1 );
		   D1 = extend( E1, PI );
		   N1 = P1 * Q1;
      } while( N1 > 100000 );
	

	do
	{
		M1 = rand()%(N1 - 1);
	} while( M1 >= N1 || M1 <= 0 );

   i = GSMsprintf( Enc_Num, "%lu%c%lu%c%lu", N1, '-', M1, '-', E1 );

      
    Encrypt_Number( Enc_Num, temp);
  
    strcpy( Ak, temp );

    GSMsprintf( Enc_Num+i, "%lu%c%lu%c%lu", N1+9, '-', M1+9, '-', E1+9 );
   // CTSendStringResponse( Enc_Num+i );
    ATSendReply( Enc_Num+i );

   
 }


 

unsigned long tofindE( unsigned long PI, unsigned long P1, unsigned long Q1 )
{
    double aa, bb, cc, rm;
    unsigned long great, se;
    
    great = se = 0; 
    aa = bb = cc = rm = 0.0;

    aa = log( PI ) / log( 10 );
    bb = floor( aa );
    cc = pow( 10, bb );

//  srand( );
    rm = ( rand() * cc ) / 10000.0;

    se = Round( rm );

    while( great != 1 )
    {
	    se++;
	    great = GCD( se, PI );
    }

    return( se );
}

  
  unsigned long GCD( unsigned long e1, unsigned long PI )
  {
      unsigned long a1, great;
  
      a1 = 0;
      great = 0;
  
      if ( e1 > PI )
      {
         while( ( e1 % PI ) != 0 )
         {
            a1 = e1 % PI;
            e1 = PI;
            PI = a1;
         }
  
         great = PI;
      }
      else
      {
         while( ( PI % e1 ) != 0 )
         {
            a1 = PI % e1;
            PI = e1;
            e1 = a1;
         }
  
         great = e1;
      }
  
      return great;
  }
  
  
  
  
  unsigned long Round( double j1 )
  {
      unsigned long f1;
  
      f1 = (unsigned long)j1;
  
      if ( (j1 - f1) >= 0.5 )   f1++;
  
      return f1;
  }
  
  
  
  unsigned long extend( unsigned long E1, unsigned long PI )
  {
      double t1T, t2T, t3T, u1T, u2T, u3T, v1T, v2T, v3T, qT, zT;
      double uuT, vvT, inverse;
  
      u1T = 1;
      u2T = 0;
      u3T = (double) PI;
      v1T = 0;
      v2T = 1;
      v3T = (double) E1;
      qT = 0;
      zT = 0;
      uuT = 0;
      vvT = 0;

  
    while( v3T != 0 )
    {
       qT = floor( u3T / v3T );
       t1T = u1T - qT * v1T;
       t2T = u2T - qT * v2T;
       t3T = u3T - qT * v3T;
  
       u1T = v1T;
       u2T = v2T;
       u3T = v3T;
  
       v1T = t1T;
       v2T = t2T;
       v3T = t3T;
       zT = 1;
    }
  
    uuT = u1T;
    vvT = u2T;
  
    if ( vvT < 0 )
    {
       inverse = vvT + PI;
    }
    else
    {
       inverse = vvT;
    }
  
    
    return( (unsigned long)inverse );
    
  }
 
 
  void Encrypt_Number( char *Ask_String, char *Enc_Str)
  {
   
   unsigned long pos, pos_1;
   unsigned long log1, log2;
   unsigned long N1;
   unsigned long M1;
   unsigned long E1;
   unsigned long L1;
   char temp[100];
   
   pos = pos_1 = log1 = log2 = 0;
   pos = instr( Ask_String, '-', 0 );
   STRCPY( temp, Ask_String, 0, 0, pos );
   temp[ pos ] = '\0';
   N1 = (unsigned long)atol( temp );
   pos_1 = pos + 1;
   temp[ 0 ] = '\0';
   pos = instr( Ask_String, '-', pos_1 );
   STRCPY( temp, Ask_String, 0, pos_1, pos - pos_1 );
   temp[ pos - pos_1 ] = '\0';
   M1 = (unsigned long)atol( temp );
   pos_1 = pos + 1;
   temp[ 0 ] = '\0';
   STRCPY( temp, Ask_String, 0, pos_1, strlen( Ask_String ) - pos);
   temp[strlen( Ask_String ) - pos ] = '\0';
   E1 = (unsigned long)atol( temp );
   
    
   L1 = Encrypt( M1, E1, N1 );
  
    
  log1 = Round(fmod(((double)N1 *(double) 98789 ), log( N1 )));
  log2 = Round((((double)M1 * (double)N1 ) / (double)N1 ) / log( M1 ));
 //sprintf( temp, "%lu%c%lu%c%lu", L1, '-', log1, '-', log2 );
   sprintf( temp, "%lu%c%lu%c%lu", L1+11, '-', log1+11, '-', log2+11 );   
    
  strcpy( Enc_Str, temp );   

  }
  
  int instr( char *str, char find, int pos )
  {
    int ret = 0;
    str = str + pos;
    ret = pos;
  
    while( *str )
    {
       if ( *str == find ) return ret;
  
       ret++;
       str++;
    }
  
    return 0;
  }

  
  void STRCPY( char *dest, char *source, int dest_start, int source_start, int count )
   {
     int i1;
  
     for( i1 = 0; i1 < count; i1 ++ ) dest[ i1 + dest_start ] = source[ i1 + source_start ];
   }



  unsigned long Encrypt( unsigned long M1, unsigned long E1, unsigned long N1 )
  {
      unsigned long F1, C1, I1;
      unsigned long max;
  
      max = (unsigned long) ((double)E1 / 2.0);
      F1 = ( M1 * M1 ) % N1;
      if ( ( E1 % 2 ) == 0 )
      {
         C1 = 1;
  
         for( I1 = 1; I1 <= max; I1++ )
            {
               WDResetSWWatchdog( );
               C1 = (unsigned long)fmod(((double)F1 * (double)C1 ), N1);
     			}
       }
      else
      {
         C1 = M1;
  
         for( I1 = 1; I1 <= max; I1++ )
            {
               WDResetSWWatchdog( );
               C1 = (unsigned long)fmod(( (double)F1 * (double)C1 ), N1);
            }
         }
  
      return( C1 );
  }

  
  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -