Bitwise XOR operation between strings

Hi!! Here i come again...
The problem this time is with encoding datas using XOR operator.
My xml string is "NSMutableString xmlString" and my key string is a "char *key". Then, i need to operate the bitwise XOR between this two strings and than send the result to the server.
How can i implement this?
I think i've to convert the two strings in NSData then make the comparison with ^ operator...is that correct?
Thank you for help

MacBook Pro 2,4 Ghz 15,4", Mac OS X (10.5.3)

Posted on Sep 9, 2008 4:22 AM

Reply
4 replies

Sep 10, 2008 8:56 PM in response to McKracken

Not sure why you would ever need to do something like this oO
The result will probably be garbage, at least not human-readable...

But maybe you can try something along the lines of

NSString* string1;
NSString* string2;
NSString* result;
result = (*string1) | (*string2);


ugly and so on, but remember Objective C is still C!
Of course this bears all kinds of the usual risks when playng with pointers and memory...

Sep 11, 2008 1:30 AM in response to McKracken

Then, i'll try to say a little more...

I've this:

NSString *myObjString = @"myString";
NSString *myObjkey = @"12345678";
char myObjresult;

then, i need to do the xor between myString and key: in C a can make this, having two char variables

char myCString;
char myCKey;
char myCResult;

myResult = char ( (int)myString ^ (int)myKey )

and it's ok in C. But in objective-c it doesn't run as I thought...i tried to make the casting on the NSString object, like this:

char myObjResult = char ( (int) myObjString ^ (int) myObjkey );

it rises no error, but i don't know how to transform myObjResult in a NSData and check it consistency. The only configuration that doesn't rise any error (but i think there's something wrong) is this:

Then, i'll try to say a little more...

I've this:

NSString *myObjString = @"myString";
NSString *myObjkey = @"12345678";
char myObjresult;

char myObjResult = char ( (int) myObjString ^ (int) myObjkey );

If I control the value of myObjResult with a NSLog("%c", myObjResult), i see a different value everytime i run my project...

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Bitwise XOR operation between strings

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.