[ create a new paste ] login | about

Link: http://codepad.org/nLPBPXiF    [ raw code | output | fork ]

C++, pasted on May 11:
#include <iostream>
using namespace std;

string XORChifer (string in, string pasw);
string XOREnCrypt(string in, string pasw);
string XORDeCrypt(string in, string pasw);

int main(){
    string text = "This is example";
    string pasw = "Unknownx";
    cout<<"Text    : "<<text <<endl;
    cout<<"Password: "<<pasw <<endl;
    string encrypt = XOREnCrypt(text, pasw);
    cout<<"EnCrypt : "<<encrypt <<endl;
    string decrypt= XORDeCrypt(encrypt, pasw);
    cout<<"DeCrypt : "<<decrypt<<endl;
    return 0;
}

string XORChifer (string in, string pasw){
    string out   = in;
    for(size_t i = 0, m = pasw.length(); i < in.length() && m; i++ )
    {
        out[i]   = out[i] ^ pasw[i % m];
    }
    return out;
}

string XOREnCrypt(string in, string pasw){
    return XORChifer(in, pasw);
}

string XORDeCrypt(string in, string pasw){
    return XORChifer(in, pasw);
}


Output:
1
2
3
4
5
6
7
8
9
Text    : This is example
Password: Unknownx
EnCrypt : OX0

DeCrypt : This is example


Create a new paste based on this one


Comments: