Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #14

Open
bolabola opened this issue Aug 28, 2018 · 1 comment
Open

fixed #14

bolabola opened this issue Aug 28, 2018 · 1 comment

Comments

@bolabola
Copy link

bolabola commented Aug 28, 2018

std::string EncryptDecrypt(std::string toEncrypt) { char key[4] = { 'j', 'T', 'J','d' }; std::string output = toEncrypt; for (int i = 0; i < toEncrypt.size(); i++) { output[i] = toEncrypt[i] ^ key[i % (sizeof(key) / sizeof(char))]; if (output[i] == 0) { output[i] = toEncrypt[i]; } } output[toEncrypt.size()] = 0; return output; }

@surioi
Copy link

surioi commented Jul 21, 2021

Original function fails, why is that? Yours seems to be good.

static string encryptDecrypt(string toEncrypt)
{
    //char k_v3[8] = {0x18, 0x1d, 0x08, 0x30, 0x6d, 0x19, 0x12, 0x6e}; // good
    //char k_v3[8] = {'1', 'z', 'w','b','j', 'U', '8','7'}; // good
    //char k_v3[8] = {'b', 'H', 'p','O','n', 'k', 'Z','M'}; // FAIL dec=[BEGIN some text to e]
    char k_v3[8] = {0x18, 0x15, 0x0e,0x1c,0x38, 0x2f, 0x6f,0x6e}; // FAIL dec=[BEGIN some text to enc]

    /*
    // FAIL dec=[BEGIN some text to enco0d ]
    char k_v3[30];
    memset(k_v3,0,sizeof(k_v3));
    strcat(k_v3,"gjw9gjw9gjw9gjw9gjw9w9gjw9gjw9");
    */

    string output = toEncrypt;
    
    for (int i = 0; i < toEncrypt.size(); i++)
    {
        output[i] = toEncrypt[i] ^ k_v3[i % (sizeof(k_v3) / sizeof(char))];
    }
    
    return output;
}

// main
std::string enc = encryptDecrypt("BEGIN some text to enco0d go-04-2k0''gf]dh][df hdf END");
printf("enc=[%s]\n",enc.c_str());

std::string dec = encryptDecrypt(enc.c_str());
printf("dec=[%s]\n",dec.c_str());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants