WORD key=1;
CString str;//已赋值
CString strRet;strRet=str;
for(i=0;i<str.GetLength();i++)
{
    strRet.SetAt(i,str.GetAt(i)^(key>>8));
    key=((BYTE)strRet.GetAt(i)+key)*10+10;
}越详细越好,因为我需要改成VB代码。测试成功即结帖,高手帮忙,在线等!

解决方案 »

  1.   

    看看这样能不能看懂:
    WORD key = 1;
    CString str;
    LPSTR strRet = str.GetBuffer(0);
    int length = str.GetLength();
    for (i=0; i <length; i++)
    {
        strRet[i] ^= (key >> 8);
        key = ((BYTE)strRet[i] + key) * 10 + 10;
    }
      

  2.   

    >>是“右移”操作,^是“异或”操作
      

  3.   

    dim Key as long
    dim str as String;
    dim strRet as String;
    dim i as longstr = StrConv(str, vbFromUnicode);
    strRet = str
    for i = 1 to lenb(str)
      mid(strRet,i,1) = chr(Asc(mid(str,i,1)) xor (key \ 256))
      key = ((Asc(mid(strRet,i,1))+Key) * 10& + 10&) and 65535
    next i
      

  4.   

    如果有问题的话,str = StrConv(str, vbFromUnicode);这个可以去掉,同时循环当中的LenB也要改为Len.
      

  5.   

    呵呵,果然有问题dim Key as long
    dim str as String;
    dim strRet as String;
    dim i as longstrRet = str
    for i = 1 to len(str)
      mid(strRet,i,1) = chr(Asc(mid(str,i,1)) xor (key \ 256))
      key = ((Asc(mid(strRet,i,1))+Key) * 10& + 10&) and 65535
    next i
      

  6.   

    dim Key as long
    dim str as String;
    dim strRet as String;
    dim i as longstr = StrConv(str, vbFromUnicode);
    strRet = str
    for i = 1 to LenB(str)
      MidB(strRet,i,1) = ChrB(AscB(MidB(str,i,1)) xor (key \ 256))
      key = ((AscB(MidB(strRet,i,1))+Key) * 10& + 10&) and 65535
    next i
    strRet = StrConv(strRet, vbUnicode);