php xorcrevasse,XOREncrypt.cpp

#include

#include

#include

#include "XOREncrypt.h"

#define CountArray(array) sizeof(array)/sizeof(array[0])

//数据大小

#define ENCRYPT_KEY_LEN6//密钥长度

//生成密文

unsigned short CXOREncrypt::EncryptData(const char * pSrcData, char * pEncrypData, unsigned short wSize)

{

//效验参数

if(wSize<=0) return 0;

if(pSrcData==NULL) return 0;

if(pEncrypData==NULL) return 0;

//初始化参数

pEncrypData[0]=0;

//生成密钥

unsigned char szRandKey[ENCRYPT_KEY_LEN];

szRandKey[0]=strlen(pSrcData);

for (int i=1;i

//生成密文

unsigned char bTempCode=0;

unsigned short wTimes=(szRandKey[0]+ENCRYPT_KEY_LEN-1)/ENCRYPT_KEY_LEN*ENCRYPT_KEY_LEN;

if ((wTimes*4+1)>wSize) return wTimes*4+1;

for (int i=0;i

{

if (i

else bTempCode=szRandKey[i%ENCRYPT_KEY_LEN]^(rand()%255);

sprintf(pEncrypData+i*4,"%02x%02x",szRandKey[i%ENCRYPT_KEY_LEN],bTempCode);

}

return wTimes*4;

}

//解开密文

unsigned short CXOREncrypt::CrevasseData(const char * pEncrypData, char *pSrcData, unsigned short wSize)

{

//效验参数

if(wSize<=0) return 0;

if(pSrcData==NULL) return 0;

if(pEncrypData==NULL) return 0;

//初始化参数

pSrcData[0]=0;

//效验长度

unsigned short wEncrypPassLen=strlen(pEncrypData);

if (wEncrypPassLen

//效验长度

char * pEnd=NULL;

char szTempBuffer[3]={pEncrypData[0],pEncrypData[1],0};

unsigned short wSoureLength=(unsigned short)strtol(szTempBuffer,&pEnd,16);

if (wEncrypPassLen!=((wSoureLength+ENCRYPT_KEY_LEN-1)/ENCRYPT_KEY_LEN*ENCRYPT_KEY_LEN*4)) return 0;

if (wSoureLength>(wSize-1)) return wSoureLength;

//解开密码

unsigned char szKeyBuffer[3];

for (int i=0;i

{

szKeyBuffer[0]=pEncrypData[i*4];

szKeyBuffer[1]=pEncrypData[i*4+1];

szKeyBuffer[2]=0;

szTempBuffer[0]=pEncrypData[i*4+2];

szTempBuffer[1]=pEncrypData[i*4+3];

szTempBuffer[2]=0;

unsigned int uKey=strtol((char *)szKeyBuffer,&pEnd,16);

unsigned int uEncrypt=strtol(szTempBuffer,&pEnd,16);

pSrcData[i]=(char)((unsigned char)uKey^(unsigned char)uEncrypt);

}

pSrcData[wSoureLength]=0;

return wSoureLength;

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值