***已得到(传奇封包)加密算法的源代码,谁能据此写个对应的解码过程啊?***

wqedsaa1 2003-11-01 01:17:24
加密算法如下:(据说和base64类似)解码代码只要能把"Vba]Wc]eW_<lIn{GzXGZlxSRghc["解成"jianxin007/所罗门之蛇就可以了!"

int WINAPI fnEncode6BitBufW(unsigned char *pszSrc, TCHAR *pszDest, int nSrcLen, int nDestLen)
{
int nDestPos = 0;
int nRestCount = 0;
unsigned char chMade = 0, chRest = 0;

for (int i = 0; i < nSrcLen; i++)
{
if (nDestPos >= nDestLen) break;

chMade = ((chRest | (pszSrc[i] >> (2 + nRestCount))) & 0x3f);
chRest = (((pszSrc[i] << (8 - (2 + nRestCount))) >> 2) & 0x3f);

nRestCount += 2;

if (nRestCount < 6)
pszDest[nDestPos++] = chMade + 0x3c;
else
{
if (nDestPos < nDestLen - 1)
{
pszDest[nDestPos++] = chMade + 0x3c;
pszDest[nDestPos++] = chRest + 0x3c;
}
else
pszDest[nDestPos++] = chMade + 0x3c;

nRestCount = 0;
chRest = 0;
}
}

if (nRestCount > 0)
pszDest[nDestPos++] = chRest + 0x3c;

pszDest[nDestPos] = L'\0';

return nDestPos;
}


...全文
424 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wqedsaa1 2003-11-01
  • 打赏
  • 举报
回复
高手就是高手!
Iamapuma 2003-11-01
  • 打赏
  • 举报
回复
I looked through this encryption function this afternoon,and I analysed its work routine. Fortunately,I got the key to decryption.The following is some data that I think useful.Now enjoy it:)
Testing Data:
Source String:jianxin007/所罗门之蛇.
Dest String:Vba]Wc]eW_<lIn{GzXGZlxSRghc[
Encryption Routine:
Loop chMade chRest nRestCount Src Dest
1 00011010 00100000 0 Src[0]=01101010 Dest[0] =chMade+0x3c
2 00100110 00100100 2 Src[1]=01101001 Dest[1]=chMade+0x3c
3 00100101 00100001 4 Src[2]=01100001 Dest[2]= chMade+0x3cDest[3]= chRest+0x3c
Since nRestCount=6,now we set ChRest and nRestCount to 0,and restart encryption process…
… …
Accroding to the above table,we can see clearly that:in the first time of loop,chRest:00100000,the 5th and 6th bit(bold part) are equal to the corresponding bits in Src[0],and these two bits are saved to the value—chMade in the second time of loop.Obviously,we can compute chMade with the dest[1],which we have to use to compute src[0].Its expression is: ((Dest[1]-0x3c)<<2)>>6,and this value is the last two bit in Src[0],now we have got Src[0],and in the same way,we can compute Src[1] with chMade,of course,Src[2] needs to be computed with chRest.Now I give the two functions.Good luck!
int WINAPI fnEncode6BitBufW(unsigned char *pszSrc, TCHAR *pszDest, int nSrcLen, int nDestLen)
{
int nDestPos = 0;
int nRestCount = 0;
unsigned char chMade = 0, chRest = 0;
for (int i = 0; i < nSrcLen; i++){
if (nDestPos >= nDestLen) break;
chMade = ((chRest | (pszSrc[i] >> (2 + nRestCount))) & 0x3f);
chRest = (((pszSrc[i] << (8 - (2 + nRestCount))) >> 2) & 0x3f);
nRestCount += 2;
if (nRestCount < 6)
pszDest[nDestPos++] = chMade + 0x3c;
else{
if (nDestPos < nDestLen - 1){
pszDest[nDestPos++] = chMade + 0x3c;
pszDest[nDestPos++] = chRest + 0x3c;
}else
pszDest[nDestPos++] = chMade + 0x3c;//In fact,I think this sentence
//is non-functional.
nRestCount = 0;
chRest = 0;
}
}
if (nRestCount > 0)
pszDest[nDestPos++] = chRest + 0x3c;
pszDest[nDestPos] = L'\0';
return nDestPos;
}
int fnDecode6BitBufW(TCHAR *pszSrc, TCHAR *pszDest, int nSrcLen, int nDestLen)
{
int nDestPos = 0;
int nRestCount = 2;
unsigned char chMade = 0, chRest = 0;
for(int i=0;i<nSrcLen-1;i++){
if(nDestPos>=nDestLen-1)
return -1;/*INSUFFCIENT_BUFFER*/
if(nRestCount<6){
unsigned char m,m1;
m=pszSrc[i]-0x3c;
m=m<<nRestCount;
m1=pszSrc[i+1]-0x3c;
m1=m1<<2;
m1=m1>>(8-nRestCount);
pszDest[nDestPos++]=m|m1;
}else{
int m,m1;
m=pszSrc[i]-0x3c;
m=m<<nRestCount;
m1=pszSrc[i+1]-0x3c;
m1=m1<<2;
m1=m1>>(8-nRestCount);
pszDest[nDestPos++]=m|m1;
i++;
}
if(nRestCount>=6)
nRestCount=2;
else
nRestCount+=2;
}
pszDest[nDestPos]='\0';
return nDestPos;
}
Iamapuma 2003-11-01
  • 打赏
  • 举报
回复
呵呵,楼上的这种加密肯定是对称加密啊,如果是不可逆散列算法,那接收方如何解密啊,不过不应该这么简单吧,否则传奇开发组不是太。。。,楼主确认吗?我觉得应该是个对称加密算法才对,不过我看看这个函数吧
SlayerCarrier 2003-11-01
  • 打赏
  • 举报
回复
帅哥,有的加密算法是不可逆的啊。最近正在学密码学,很多还不懂。
crazy_lazy_pig 2003-11-01
  • 打赏
  • 举报
回复
gz
wqedsaa1 2003-11-01
  • 打赏
  • 举报
回复
up

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧