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

📄 encryption.c

📁 基于ST72324设计的汽车无钥匙开门源程序
💻 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);
	
}	

⌨️ 快捷键说明

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