Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty

    I don't get it? This Should work?!

    THIS POST NO LONGER APPLIES. READ THIS ONE

    Okay I've got a program that encrypts text with a key:
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    void XOREncrypt(char* key, char* plaintext);
    
    int main()
    {
        char plaintext[50];
        char key[50];
        
        for(;;)
        {
         cout<<"Plaintext file name: ";
         cin >> plaintext;
         cout<<"Encryption Key: ";
         cin >> key;
         XOREncrypt(key, plaintext);
        }
        return 1;
    }
    
    void XOREncrypt(char* key, char* plaintext)
    {
                     fstream plainfile(plaintext, ios::in | ios::out | ios::binary);
                     if(!plainfile)
                     {
                                    cout <<"Error opening plaintext.\n";
                                    return;
                                    }
                     fstream cipherfile("ciphertext.txt", ios::in | ios::out | ios::binary | ios::trunc);
                     if (!cipherfile)
                     {
                                     cout << "Error opening chiphertext.txt.\n";
                                     return;
                                     }     
                     int i = 0;
                     char ch;
                     while(plainfile)
                     {
                      plainfile.get(ch);
                      if(plainfile)
                      {
                            cipherfile.put(ch ^ key[i]);
                            i++;
                            if(!key[i]) i = 0;
                      }
                     }
                     cout<< "XOR Encryption finished. Check ciphertext.txt" << endl;
                     return;
    }
    Just a simple XOR routine.
    The key is: "key"

    So now I have the plain text, and the cipher text:
    Quote Originally Posted by plaintext
    Hello my name is Shaun.
    Quote Originally Posted by ciphertext
    #
    YYEE*K
    Ok. So now it would make sense to me that XORing the plaintext with the ciphertext would reveal the key.
    for instance:
    0000 1111 - plain
    ^1111 0000 - cipher
    1111 1111 - key

    See what I mean? So I made this program to do just that:


    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    void XOREncrypt(char* ciphertext, char* plaintext);
    
    int main()
    {
        char plaintext[50];
        char ciphertext[50];
        
        for(;;)
        {
         cout<<"Plaintext file name: ";
         cin >> plaintext;
         cout<<"Ciphertext filename: ";
         cin >> ciphertext;
         XOREncrypt(ciphertext, plaintext);
        }
        return 1;
    }
    
    void XOREncrypt(char* ciphertext, char* plaintext)
    {
                     fstream plainfile(plaintext, ios::in | ios::out | ios::binary);
                     if(!plainfile)
                     {
                                    cout <<"Error opening plaintext.\n";
                                    return;
                                    }
                     fstream cipherfile(ciphertext, ios::in | ios::out | ios::binary);     
                     if (!cipherfile)
                     {
                                     cout << "Error opening chiphertext.\n";
                                     return;
                                     }           
                     fstream keyfile("key.txt", ios::in | ios::out | ios::binary | ios::trunc);
                     if(!keyfile)
                     {
                                 cout << "Error opening key.txt\n";
                                 return;
                                 }
                     
                     int i = 0;
                     char ch1, ch2;
                     while(plainfile && cipherfile)
                     {
                      plainfile.get(ch1);
                      cipherfile.get(ch2);
                      if(plainfile && cipherfile)
                      {
                            keyfile.put(ch1 ^ ch2);
                      }
                     }
                     cout<< "XOR Encryption finished. Check ciphertext.txt" << endl;
                     return;
    }
    Simple as pie...

    Except instead of getting the key. I get this mess!:

    Quote Originally Posted by mess
    ·›OlO xy'nkm< os<S1apn*
    might I ask? Wtf?! my head is smitten by new mistress and perplexity is her name.

    Hmmm.. I should have checked the encryptor after I edited it. It seems like every little thing I do to it messes up the code immensely.

    The closest thing I have got to fixing it is this:
    HEllo, my namE is Shaun..)
    and it keeps throwing in random capitalization and shit... I don't get it o_O... Is it so much to ask for something to just work?

    EDIT:
    Using this scheme...
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    void XOREncrypt(char* key, char* plaintext);
    
    int main()
    {
        char* plaintext = new char[50];
        char* key = new char[50];
        
        for(;;)
        {
         plaintext = new char[50];
         key = new char[50];
         cout<<"Plaintext file name: ";
         cin >> plaintext;
         cout<<"Encryption Key: ";
         cin >> key;
         XOREncrypt(key, plaintext);
        }
        return 1;
    }
    
    void XOREncrypt(char* key, char* plaintext)
    {
                     fstream plainfile(plaintext, ios::in | ios::out | ios::binary);
                     if(!plainfile)
                     {
                                    cout <<"Error opening plaintext.\n";
                                    return;
                                    }
                     fstream cipherfile("ciphertext.txt", ios::in | ios::out | ios::binary | ios::trunc);
                     if (!cipherfile)
                     {
                                     cout << "Error opening chiphertext.txt.\n";
                                     return;
                                     }     
                     int i = 0;
                     char ch;
                     while(plainfile)
                     {
                      plainfile.get(ch);
                      if(!plainfile)break;
                      if(ch)
                      {
                            cipherfile.put(ch ^ key[i]);
                            i++;
                            if(!key[i]) i = 0;
                      }
                     }
                     cout<< "XOR Encryption finished. Check ciphertext.txt" << endl;
                     return;
    }
    I almost fixed it....

    but the E is still capitalized....
    HEllo my name is Shaun.
    Why is this so fkin complicated D: ArGGGHH! It's supposed to be easy!
    Last edited by why06; 12-11-2009 at 11:15 PM.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  2. #2
    Obama's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    The Black house
    Posts
    22,195
    Reputation
    870
    Thanks
    6,076
    My Mood
    Cool
    Its been 2 hours. Just wait

  3. #3
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    What compiler are you using why?
    My MSVC++ 2003 complains about 'while(plainfile)'
    Ah we-a blaze the fyah, make it bun dem!

  4. #4
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Hell_Demon View Post
    What compiler are you using why?
    My MSVC++ 2003 complains about 'while(plainfile)'
    Yeh well Im making it too complicated. Here this one i simple enough that anyone can analyze it quickly:

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        char p,c,k;
        p = 'p';//plain
        c = 'c';//cipher
        k = 'k';//key
        cout<<p<<endl; //prints plain character to screen
        
        c = p^k;
        cout<<c<<endl; //prints cipher character to screen
        
        k = c^p;
        cout<<k<<endl; //prints key to screen
        
        //Time for strings... these are more error prone//
        char* pp = new char[50];
        char* cp = new char[50];
        char* kp = new char[50];
        strcpy(pp,"plaintext plaintext plaintext");
        strcpy(cp,"cipher");
        strcpy(kp, "key");
        cout<<pp<<endl;
        
        //XORs plaintext with key
        for(int i = 0; pp[i]; i++)
        {
            if(!*kp)kp = "key";
            cp[i] = pp[i] ^ *(kp++);
        }
        cout << cp <<endl; // prints ciphertext to screen
        
        //XORs plaintext with cipertext. This should reveal key
        char* t = new char[50];
        for(int i = 0; pp[i]; i++)
        {
             t[i] = pp[i] ^ cp[i];
        }
        cout<< t <<endl; //prints keytext to screen
        
        system("pause");
        
        return 1;
    }

    Quote Originally Posted by Output
    p

    k
    plaintext plaintext plaintext
    K§§ ↑☻♂
    ♀↨▼
    keykeykeykeykeykeykeykeykeykeSORS=2
    See the key is revealed, but there are also some errors tacked on to the end.(SORS=2) Now it seems the longer the text gets the worse the errors. So I need to nip this out. I know I have played out this XOR thing, but it's important that I get it exactly right! If there are errors in my own algorithms, especially one this simple... how can I hope to crack others encryption?

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  5. #5
    Matrix_NEO006's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Posts
    240
    Reputation
    12
    Thanks
    33
    My Mood
    Lonely
    u defined key as char and char is ' ' not " ". unless you convert it with sZ.
    u need to convert char to string.
    https://www.linuxquestions.org/questi...r-in-c-423771/
    Last edited by Matrix_NEO006; 12-11-2009 at 10:51 PM.

  6. #6
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Matrix_NEO006 View Post
    u defined key as char and char is ' ' not " ". unless you convert it with sZ.
    u need to convert char to string.
    What line are you talking about? Can you show me?

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  7. #7
    Matrix_NEO006's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Posts
    240
    Reputation
    12
    Thanks
    33
    My Mood
    Lonely
    Quote Originally Posted by why06 View Post
    What line are you talking about? Can you show me?
    if(!*kp)kp = "key";

  8. #8
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Matrix_NEO006 View Post
    if(!*kp)kp = "key";
    kp is a char*

    here is the declaration: char* kp = new char[50];

    So I can do that.... =/

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  9. #9
    Matrix_NEO006's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Posts
    240
    Reputation
    12
    Thanks
    33
    My Mood
    Lonely
    usually char should be like this
    if(!*kp)kp = 'key';

  10. #10
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Matrix_NEO006 View Post
    usually char should be like this
    if(!*kp)kp = 'key';
    lol it's not a char, it is a char*... You may be confused because I tested the value of kp rather then index it like usual e.g. (kp[i]) Also I incremented the pointer using (kp++)

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  11. #11
    Obama's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    The Black house
    Posts
    22,195
    Reputation
    870
    Thanks
    6,076
    My Mood
    Cool
    -sigh, this shit is WAY over mah head.

  12. The Following User Says Thank You to Obama For This Useful Post:

    why06 (12-11-2009)

  13. #12
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Obama View Post
    -sigh, this shit is WAY over mah head.
    Lol. No worries bro. You were right about me giving up too soon. Hopefully BlackAngel or Jetamay will stop in. Not like Im in a rush. I have a million things to do before schools out and this isn't a high priority.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  14. #13
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    Quote Originally Posted by why06 View Post
    Lol. No worries bro. You were right about me giving up too soon. Hopefully BlackAngel or Jetamay will stop in. Not like Im in a rush. I have a million things to do before schools out and this isn't a high priority.
    I hate you. LOL, made me come back to programming. After that, 'inspiring conversation' on MSN. LOL

    Decided I'll do a bit of both, mix it up with Graphics, and Programming.

  15. #14
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Uhm mister why, this works fine for me:
    Code:
    #include <windows.h>
    #include <iostream>
    #include <fstream>
    using namespace std;
    void XOREncrypt(int num, int key);
    
    int main()
    {
    	int num=00001101;
    	int key=10100000;
    	while(1)
    	{
            cout<<"Enter a number: ";
    		cin >> num;
    		if(num==9001)
    		{
    			break;
    		}
    		cout<<"Encryption Key: ";
    		cin >> key;
    		XOREncrypt(num, key);
    	}
        return 1;
    }
    
    void XOREncrypt(int num, int key)
    {
    	cout<<"XOR Encryption finished. Here is the result: "<<(num ^ key) << endl;
    }
    Using numbers that works fine, try converting the char they enter to int first see if that works.
    Ah we-a blaze the fyah, make it bun dem!

  16. #15
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Hell_Demon View Post
    Uhm mister why, this works fine for me:


    Using numbers that works fine, try converting the char they enter to int first see if that works.
    That might be the best way. Or just do it absolutely 1 char at a time. not using strings at all. I'll experiment around with some different techniques to see which is most error prone.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

Page 1 of 2 12 LastLast

Similar Threads

  1. THIS IS HOW YOU GET YOUR CA TO WORK 100%
    By tyler911 in forum Combat Arms Help
    Replies: 15
    Last Post: 10-30-2009, 09:45 PM
  2. this is for anyone who cant get the aimbot to work and has AVG
    By jmonking in forum Combat Arms Europe Hacks
    Replies: 8
    Last Post: 09-11-2009, 04:51 AM
  3. STICKY THIS!!! ALL NOOBS WHO CANT GET CA HACKS TO WORK OR DC IN GAME COME HERE!!!!
    By Jacobas in forum Suggestions, Requests & General Help
    Replies: 1
    Last Post: 01-02-2009, 09:48 AM
  4. This should help you NOT get D/C anymore.
    By Tinnytim in forum Combat Arms Hacks & Cheats
    Replies: 18
    Last Post: 12-23-2008, 07:57 PM
  5. This should help you NOT get D/C anymore.
    By Tinnytim in forum Combat Arms Hacks & Cheats
    Replies: 6
    Last Post: 12-23-2008, 07:46 PM