赞
踩
- void Encrypt(unsigned char* pdata,int len,unsigned long key0,unsigned long key1)
- {
- union sDWORD
- {
- unsigned long ldata;
- unsigned char b[4];
- };
- union sWORD
- {
- short a;
- struct
- {
- unsigned char b0;
- unsigned char b1;
- }b;
- };
- union DISPLAY
- {
- struct{ unsigned char v; }B;
- struct {
- unsigned char b0 :1; unsigned char b1 :1; unsigned char b2 :1; unsigned char b3 :1; unsigned char b4 :1; unsigned char b5 :1; unsigned char b6 :1; unsigned char b7 :1;
- }b;
- };
- unsigned char *ps=pdata;
- int ByteLengthBak=len;
- union sDWORD p;
- union sDWORD k;
- DISPLAY c;
- p.ldata=key1;
- k.ldata=key0;
- char buffer1,buffer2;
- unsigned char RBKEY=p.b[0];
- unsigned char RBKEY1=p.b[3];
- unsigned char RBKEY2=p.b[1];
- unsigned char RBKEY3=p.b[2];
- RBKEY^=key0;
- buffer1=p.b[1];
- p.b[1]=k.b[3];
- buffer2=p.b[3];
- p.b[3]=k.b[1];
- k.b[1]=buffer1;
- k.b[3]=buffer2;
- int count=0;
- while(len)
- {
- if (count==8) count=0;
- if(count<4)
- {
- *(pdata++)^=k.b[count];
- }
- else
- {
- *(pdata++)^=p.b[count-4];
- }
- count++;
- len--;
- }
- for(int ii=0;ii<ByteLengthBak;ii++)
- {
- ps[ii]=ps[ii]^(RBKEY);
- c.B.v=ps[ii];
- c.b.b0^=(RBKEY1&0x1);
- c.b.b2^=((RBKEY1&0x2)>>1);
- c.b.b4^=((RBKEY1&0x4)>>2);
- c.b.b6^=((RBKEY1&0x8)>>3);
- c.b.b7^=((RBKEY1&0x80)>>7);
- c.b.b1^=c.b.b3;
- c.b.b3^=c.b.b5;
- c.b.b5^=c.b.b7;
- c.b.b5^=p.b[0];
- c.b.b3^=p.b[1];
- c.b.b1^=p.b[2];
- c.b.b7^=p.b[3];
- c.b.b0^=(RBKEY2&0x1);
- c.b.b2^=((RBKEY3&0x4)>>1);
- c.b.b4^=((RBKEY2&0x8)>>3);
- c.b.b6^=((RBKEY3&0x80)>>7);
- }
- }
- void Encrypt(unsigned char* pdata,int len,string key)
- {
- CMD5 md5;
- md5.GenerateMD5 ((unsigned char*)key.c_str (),key.length ());
- Encrypt(pdata,len,md5.m_data[0]^md5.m_data[3],md5.m_data[1]^md5.m_data[2]);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。