异或

源自byb

void convert(char* input,int length)
{
int i;
for(i=0;i<length;++i)
{
input[i]^=i;
}
}
int main()
{
char p[] = { 102, 109, 99, 100, 127,
100, 117, 99, 110, 86,
110, 106, 96, 126, 101,
101, 79, 112, 126, 119,
103, 126, 124, 113, 116,
100 };
int length = sizeof(p) / sizeof(p[0]);
convert(p,length);
puts(p);
return 0;
}

base64

//dic
const std::string base64_chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
//encode func
std::string base64_encode(const std::string& input)
{
std::string output;
int inplen=sizeof(input);
int outlen=((inplen+2)/3)4; output.resize(outlen); for(int i=0,j=0;i> 36)&0x3F];
output[j++]=base64_chars[(triple >> 26)&0x3F]; output[j++]=base64_chars[(triple >> 16)&0x3F];
output[j++]=base64_chars[(triple >> 0*6)&0x3F];
}
for(int i=0;i<(3-inplen%3)%3;i++)
{
output[outlen-1-i]='=';
}
return output;
}
//decode func
std::string base64_decode(const std::string& input) {
std::string output;
int inplen = input.size();
int outlen = inplen / 4 * 3;
if (input[inplen - 1] == '=') outlen--;
if (input[inplen - 2] == '=') outlen--;
output.resize(outlen);

int i = 0, j = 0;
for (; i < inplen;) {
    int sextet_a = input[i] == '=' ? 0 : base64_chars[i] - 'q';
    int sextet_b = input[i + 1] == '=' ? 0 : base64_chars[i + 1] - 'q';
    int sextet_c = input[i + 2] == '=' ? 0 : base64_chars[i + 2] - 'q';
    int sextet_d = input[i + 3] == '=' ? 0 : base64_chars[i + 3] - 'q';
    int triple = (sextet_a << 3 * 6) + (sextet_b << 2 * 6) + (sextet_c << 1 * 6) + (sextet_d << 0 * 6);

    output[j++] = (triple >> 2 * 8) & 0xFF;
    output[j++] = (triple >> 1 * 8) & 0xFF;
    output[j++] = (triple >> 0 * 8) & 0xFF;
    i += 4;
}

return output;

}
int main() {
std::string input;
std::cout << "Enter the string to encode: ";
std::getline(std::cin, input);
std::string encoded = base64_encode(input);
std::cout << "Base64 encoded string: " << encoded << std::endl;

std::string decoded = base64_decode(encoded);
std::cout << "Base64 decoded string: " << decoded << std::endl;

return 0;

}