doutao5419 2017-04-07 05:20
浏览 65

Translit xor crypting c ++ to php

I want to translit xor crypting c++ to php. I use this function for crypting. I want decrypt this file with php.

wchar_t* encryptDecrypt(const wchar_t* toEncrypt, int length,   wchar_t* EBKey) {
    const wchar_t* key = EBKey;
    wchar_t* output = new wchar_t[length];

    for (int i = 0; i < length; i++) {
        output[i] = toEncrypt[i] ^ key[i % wcslen(key)];
    }
    return output;
}

I read a xls file binary and crypt with encryptDecrypt

void encryptAndSave(char *src,AnsiString key) {
    wchar_t *content;
    wchar_t  buffer[255];
    wchar_t *result;

    long size;
    long fsize;

    FILE *f=NULL;

    f=fopen(src,"rb+");

    fseek(f, 0, SEEK_END);
    size = ftell(f);
    fseek(f,0, SEEK_SET);

    content = (wchar_t *) malloc(size * sizeof (wchar_t));
    fread(content, size, 1, f);
    fclose(f);

    content=encryptDecrypt(content,size,strToWchar_t(key));

    f=fopen(src,"wb+");
    fwrite(content, size, 1, f);
    fclose(f);
}

I use this function to convertion key in to wchar_t

wchar_t* strToWchar_t(AnsiString value) {
    int iSize = value.WideCharBufSize();
    wchar_t *tmp = new wchar_t[iSize];

    value.WideChar(tmp,iSize);
    return tmp;
}

This code in php for decrypting

function encryptDecrypt($toEncrypt,$key) {
    $output=array();
    for ( $i = 0; $i < strlen($toEncrypt); $i++ ) {
        $output[$i]= $toEncrypt[$i] ^ $key{$i % strlen($key)};
    }
    return $output;
} 

But it is not rightly decrypting.When i crypt and decrypt with c++ this word, the result must be "qwerty" to "ﻎCDT@GH", but in php it does not work as c++. When i decrypt "ﻎCDT@GH" in php i get "яМp1v3e2s1u3y2", but i must get "qwerty". Please help to resolve this problem.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了