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

📄 kee(07-25-20-44-30).cpp

📁 4byte加密 唯一输出 可用于产品序列号处理
💻 CPP
字号:


#define uchar unsigned char
typedef struct
{
	  unsigned d0 : 1;
	  unsigned d1 : 1;
	  unsigned d2 : 1;
	  unsigned d3 : 1;
	  unsigned d4 : 1;
	  unsigned d5 : 1;
	  unsigned d6 : 1;
	  unsigned d7 : 1;
} modle_bit;
typedef union
{
	  modle_bit     bit ;
      unsigned char byte;
} modle_union;
modle_union moden;
typedef struct {
	unsigned d10 : 1;
	unsigned d11 : 1;
	unsigned d12 : 1;
	unsigned d13 : 1;
	unsigned d14 : 1;
	unsigned d15 : 1;
	unsigned d16 : 1;
	unsigned d17 : 1;
	unsigned d20 : 1;
	unsigned d21 : 1;
	unsigned d22 : 1;
	unsigned d23 : 1;
	unsigned d24 : 1;
	unsigned d25 : 1;
	unsigned d26 : 1;
	unsigned d27 : 1;
	unsigned d30 : 1;
	unsigned d31 : 1;
	unsigned d32 : 1;
	unsigned d33 : 1;
	unsigned d34 : 1;
	unsigned d35 : 1;
	unsigned d36 : 1;
	unsigned d37 : 1;
	unsigned d40 : 1;
	unsigned d41 : 1;
	unsigned d42 : 1;
	unsigned d43 : 1;
  	unsigned d44 : 1;
	unsigned d45 : 1;
	unsigned d46 : 1;
	unsigned d47 : 1;
} kee_bit;
typedef struct
{
	unsigned char byte1;
	unsigned char byte2;
	unsigned char byte3;
	unsigned char byte4;
} kee_byte;
typedef union
{
	kee_bit     bit ;
    kee_byte    byte;
    unsigned long word;
} kee_union;


  c1=11+1;c0=48;		//默认是 c1=12 c0=48
  for(cou1=0L;cou1<0x10;cou1++){

  keyl.word=0x23452301;
  keyh.word=0xefaaab89;

  hop.word=cou1;

  code(c1,c0);
#ifdef printf_debug
  printf(" %02x",hop.byte.byte1);
  printf(" %02x",hop.byte.byte2);
  printf(" %02x",hop.byte.byte3);
  printf(" %02x",hop.byte.byte4);
  printf("    ");
#endif
  fwrite(&(hop.byte.byte1),1,1,fb);
  fwrite(&(hop.byte.byte2),1,1,fb);
  fwrite(&(hop.byte.byte3),1,1,fb);
  fwrite(&(hop.byte.byte4),1,1,fb);

  decode(c1,c0);
#ifdef printf_debug
  printf(" %02x",hop.byte.byte1);
  printf(" %02x",hop.byte.byte2);
  printf(" %02x",hop.byte.byte3);
  printf(" %02x",hop.byte.byte4);
  printf("\n");
#endif

//以keyh,keyl为密钥 对hop的数据进行kee加密,结果还在hop里。(c1 c0 标准直是 12 48)
int code(uchar c1,uchar c0)
{uchar cnt0,cnt1;
 modle_union mask;
 modle_union btemp;
 uchar temp;

 cnt1=c1;
outer:
 cnt0=c0;
inner:
 if(cnt1==c1)goto rot_key;
 mask.byte=0x01;
 if(hop.bit.d34==1)mask.byte=0x10;
 if(hop.bit.d21==1)mask.byte=mask.byte<<2;
 if(hop.bit.d11==1)mask.byte=mask.byte<<1;

      if((hop.bit.d47==0)&&(hop.bit.d42==0))temp=(uchar) (0x2e);
 else if((hop.bit.d47==0)&&(hop.bit.d42==1))temp=(uchar) (0x74);
 else if((hop.bit.d47==1)&&(hop.bit.d42==0))temp=(uchar) (0x5c);
 else if((hop.bit.d47==1)&&(hop.bit.d42==1))temp=(uchar) (0x3a);

 mask.byte=temp&mask.byte;
 if(mask.byte==0x00)temp=0x00;
 else          temp=0x01;

 temp=temp^hop.byte.byte3;
 temp=temp^hop.byte.byte1;
 temp=temp^keyl.byte.byte3;

 mask.byte=temp;

 hop.word   =hop.word>>1;
 hop.bit.d47=mask.bit.d0;

rot_key:

 btemp.bit.d0=keyl.bit.d10;

 keyl.word=keyl.word>>1;
 keyl.bit.d47=keyh.bit.d10;

 keyh.word=keyh.word>>1;
 keyh.bit.d47=btemp.bit.d0;

 cnt0--;
 if(cnt0!=0) goto inner;
 cnt1--;
 if(cnt1!=0) goto outer;

return 0;
}
//以keyh,keyl为解密密钥 对hop的数据进行kee解密,结果还在hop里。(c1 c0 标准直是 12 48)
int decode(uchar c1,uchar c0)
{uchar cnt0,cnt1;
 modle_union mask;
 modle_union btemp;
 uchar temp;
 cnt1=c1;
outer:
 cnt0=c0;
inner:
 if(cnt1==1)goto rot_key;
 mask.byte=0x01;
 if(hop.bit.d33==1)mask.byte=0x10;
 if(hop.bit.d20==1)mask.byte=mask.byte<<2;
 if(hop.bit.d10==1)mask.byte=mask.byte<<1;

      if((hop.bit.d46==0)&&(hop.bit.d41==0))temp=0x2e;
 else if((hop.bit.d46==0)&&(hop.bit.d41==1))temp=0x74;
 else if((hop.bit.d46==1)&&(hop.bit.d41==0))temp=0x5c;
 else if((hop.bit.d46==1)&&(hop.bit.d41==1))temp=0x3a;

 mask.byte=temp&mask.byte;
 if(mask.byte==0x00)temp=0x00;
 else          temp=0x80;

 temp=temp^hop.byte.byte2;
 temp=temp^hop.byte.byte4;
 temp=temp^keyl.byte.byte2;

 mask.byte=temp;
 hop.word =hop.word<<1;
 hop.bit.d10=mask.bit.d7;

rot_key:
 btemp.bit.d7=keyh.bit.d47;
 keyh.word=keyh.word<<1;
 keyh.bit.d10=keyl.bit.d47;

 keyl.word=keyl.word<<1;
 keyl.bit.d10=btemp.bit.d7;

 cnt0--;
 if(cnt0!=0) goto inner;
 cnt1--;
 if(cnt1!=0) goto outer;

return 0;
}

⌨️ 快捷键说明

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