www.pudn.com > Encryption.rar > Encryption.c


#include "Subroutine.h" 
unsigned int long  tempTable; 
unsigned int long Encryption(unsigned long int outdata,unsigned long int IDCode,enum encrypttype EncryptType) 
{ 
    unsigned char NLFOUT(unsigned int long code); 
    unsigned char Sample2Bit(unsigned int long code); 
    unsigned int long  TempIntLong=IDCode,TMKey=IDCode; 
    unsigned char i,k=32,temp,*p; 
    p=(unsigned char*)&TempIntLong+3; 
  	tempTable=(unsigned int)IDCode^0xba6c; 
	  tempTable<<=16; 
	  tempTable+=(unsigned int)IDCode^0xba6c; 
    if(EncryptType==Encrypt) 
    { 
       k=32; 
       while(k--) 
        { 
   i=NLFOUT(outdata)^(((unsigned char)TMKey)&0x01)^Sample2Bit(outdata); 
	 outdata<<=1; 
	 outdata|=i; 
	 TMKey>>=1; 
        } 
    } 
    else 
    { 
       TMKey=0; 
       for(i=0;i<32;i++) 
        { 
         TMKey<<=1; 
         TMKey+=(*p&0x01); 
         TempIntLong>>=1; 
        } 
       p=(unsigned char*)&outdata; 
       k=32; 
       while(k--) 
	{ 
	 temp=(unsigned char)(outdata)& 0x01; 
	 outdata>>=1; 
	 i=NLFOUT(outdata)^((unsigned char)TMKey&0x01)^((unsigned char)(outdata>>16)&0x01)^temp; 
	 TMKey>>=1; 
	  if(i) 
          *p|=0X80; 
        }	 
 
    } 
    return(outdata); 
} 
 
 
 
unsigned char NLFOUT(unsigned int long code) 
{ 
	unsigned char i=0,j; 
//	unsigned int long  temp=0x3e57ba6c; 
	for(j=0;j<4;j++) 
	{ 
	i|=((unsigned char)(code>>=6)&0x01); 
	i<<=1; 
  } 
	i|=((unsigned char)(code>>=6)&0x01); 
  return ((tempTable>>i)&0x01); 
} 
 
unsigned char Sample2Bit(unsigned int long code) 
{ 
	unsigned char i; 
	i=((unsigned char)(code>>31)& 0x01)^((unsigned char)(code>>16)&0x01); 
	return (i); 
	 
}