CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 35 of 35
  1. #31
    Join Date
    May 2012
    Posts
    43

    Re: Using this XOR encryption in C++

    Thanks monarch_dotra, that did work.
    But it uses iostream which adds about 400kb to my binsize. I prefer to not use that.

    Am I right that a char array encryption is basically not possible without using a vector in C++?
    I want to know the solution without vector if it is even possible.
    Last edited by qwerz; June 6th, 2012 at 08:30 AM.

  2. #32
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Using this XOR encryption in C++

    Quote Originally Posted by qwerz View Post
    Thanks monarch_dotra, that did work.
    But it uses iostream which adds about 400kb to my binsize. I prefer to not use that.
    Where is iostream used in the function? The only thing in the XOR function is std::string, and that is not iostream.

    Regards,

    Paul McKenzie

  3. #33
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Using this XOR encryption in C++

    Quote Originally Posted by qwerz View Post
    Am I right that a char array encryption is basically not possible without using a vector in C++?
    Eveyone has shown you what to do.

    Forget about XOR for a moment -- what about any function that returns a char* and takes a char* and const char* as parameters? Do you think that no such function can ever exist? Of course not.
    Code:
    #include <cstring>
    
    int main()
    {
        char p[100];
        strcpy(p, "abc123");
        char* returnValue = strcat(p, "This is concatenated");
    }
    So how is it that the strcat() seems to compile and work? It has the exact same signature as your XOR function.

    http://www.cplusplus.com/reference/c...string/strcat/

    So what makes it special? Absolutely nothing. The problem is that you seem to have trouble using such functions, and I don't know exactly what trouble you're having.

    Regards,

    Paul McKenzie

  4. #34
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Using this XOR encryption in C++

    Quote Originally Posted by qwerz View Post
    Thanks monarch_dotra, that did work.
    But it uses iostream which adds about 400kb to my binsize. I prefer to not use that.
    Code:
    #include <string>
    
    std::string XOR(const std::string& sentence, const std::string& key)
    {
        std::string ret(sentence);
    
        const size_t sentence_size = sentence.size();
        const size_t key_size      = key.size();
    
        for (size_t i = 0; i<sentence_size; ++i)
        {ret[i] ^= key[i &#37; key_size];}
    
        return ret;
    }
    
    int main()
    {
        std::string encoded = XOR("This is my secret sentence", "ANDthisISmyKEY");
    }
    Compiled using Visual Studio 2010. The executable size for Release mode is 9,728 bytes, not 400k bytes.

    Regards,

    Paul McKenzie

  5. #35
    Join Date
    May 2012
    Posts
    43

    Re: Using this XOR encryption in C++

    Paul thanks for all your help and the others that responded here too. I finally got it now. It was lack of C++ knowledge I guess.

    Btw I also found a way to encrypt bytearrays without the char vector that you used.
    It is just by using an LPBYTE argument instead, and the XOR worked.

    This thread could be closed if someone else does not need it.

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured