|
-
June 6th, 2012, 08:09 AM
#31
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.
-
June 6th, 2012, 09:01 AM
#32
Re: Using this XOR encryption in C++
 Originally Posted by qwerz
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
-
June 6th, 2012, 09:10 AM
#33
Re: Using this XOR encryption in C++
 Originally Posted by qwerz
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
-
June 6th, 2012, 09:26 AM
#34
Re: Using this XOR encryption in C++
 Originally Posted by qwerz
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 % 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
-
June 6th, 2012, 10:12 AM
#35
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|