xor

Is it good practice to use the XOR (^) operator in Java for boolean checks?

I personally like the 'exclusive or' operator when it makes sense in context of boolean checks because of its conciseness. I much prefer to write if (boolean1 ^ boolean2) { //do it } than if((boolean1 && !boolean2) || (boolean2 && !boolean1)) { //do it } but I often get confused looks (from other experienced java developers, n...

Exclusive Or in Regular Expression

Hey Folks! Looking for a bit of regex help. Id like to design an expression that matches a string with "foo" OR "bar" but not both "foo" AND "bar" If I do something like... /((foo)|(bar))/ Itll match "foobar". Not what Im looking for. So, how can I make regex match only when one term or the other is present? Thanks! ...

How does XOR variable swapping work?

Can someone explain to me how XOR swapping of two variables with no temp variable works? void xorSwap (int *x, int *y) { if (x != y) { *x ^= *y; *y ^= *x; *x ^= *y; } } I understand WHAT it does, but can someone walk me through the logic of how it works? ...

Char ^= 0xB3 equivalent in VBScript

I have the following C++ code: Char ^= 0xB3; Char is a single character in a string. Is there an equivalent in VBScript? ...

How do you compute the XOR Remainder used in CRC?

I'm trying to remember how the math is worked out to compute the remainder of an XOR algorithm in Cyclical Redundancy Checks to verify the remainder bits of a network message. I shouldn't have tossed that text book. This is easily done in code, but how is it worked out by hand? I know it looks something like a standard division algori...

Xor of string in ruby

Hi, I have a string, lets say "123|ABC|test|12345|FF" and I want to xor the ascii value of each character and print the result in hex. What is the simplest way? ...

How do you implement XOR using +-*/ ?

How can the XOR operation (on two 32 bit ints) be implemented using only basic arithmetic operations? Do you have to do it bitwise after dividing by each power of 2 in turn, or is there a shortcut? I don't care about execution speed so much as about the simplest, shortest code. Edit: This is not homework, but a riddle posed on a hacker....

EXCEL XOR multiple bits

Okay I have two cells with a string of bits 0111010 and 0101011. I want to XOR the two together so that the resulting cell would be 0010001. I know you can use this for boolean values =OR(AND(A1,NOT(A2)),AND(A2,NOT(A1))) but it doesn't work for a string of bits. ...

Keyword for exclusive or in ruby?

Does Ruby have a plain-English keyword for exclusive or, like they have "and" and "or"? If not, is this because exclusive or doesn't allow evaluation short-cutting? ...

Is there something wrong with BitArrays in C#?

When I conpile this code: BitArray bits = new BitArray(3); bits[0] = true; bits[1] = true; bits[2] = true; BitArray moreBits = new BitArray(3); bits[0] = true; bits[1] = true; bits[2] = true; BitArray xorBits = bits.Xor(moreBits); foreach (bool bit in xorBits) { Console.WriteLine(bit); } I get the following output: True ...

Creating a "logical exclusive or" operator in Java

Observations: Java has a logical AND operator. Java has a logical OR operator. Java has a logical NOT operator. Problem: Java has no logical XOR operator, according to sun. I would like to define one. Method Definition: As a method it is simply defined as follows: public static boolean logicalXOR(boolean x, boolean y) { retu...

Why is there no ^^ operator in C/C++?

& has &&. | has ||. Why doesn't ^ have ^^? I understand that it wouldn't be short-circuiting, but it would have different semantics. In C, true is really any non-zero value. Bitwise XOR is not always the same thing as logical XOR: int a=strcmp(str1,str2);// evaluates to 1, which is "true" int b=strcmp(str1,str3);// evaluates to 2, whic...

Check if only one variable in a list of variables is set.

I'm looking for a simple method to check if only one variable in a list of variables has a True value. I've looked at this logical xor post and is trying to find a way to adapt to multiple variables and only one true. Example >>>TrueXor(1,0,0) True >>>TrueXor(0,0,1) True >>>TrueXor(1,1,0) False >>>TrueXor(0,0,0,0,0) False ...

What's wrong with XOR encryption?

I wrote a short C++ program to do XOR encryption on a file, which I may use for some personal files (if it gets cracked it's no big deal - I'm just protecting against casual viewers). Basically, I take an ASCII password and repeatedly XOR the password with the data in the file. Now I'm curious, though: if someone wanted to crack this, h...

Game solving algorithm (Buttonia, lights-out variant)

I am trying to create a solvability function for a game algorithm. Basically a function that returns true or false for a given game it if is solvable or not. The game is Buttonia.com (which does not implement the algorithm as yet), a type of lights-out game. Basically You have a grid of buttons, each of which, when pressed, will change ...

Encryption: reversing bitwise and bitshift?

I'm trying to reverse an XOR encryption. I have the encryption code: // Walk the 16 nibbles in the 64 bit long long, selecting the corresponding key digit // and XORing it into the result. unsigned long long result = 0; for( i=0; i<16; i++ ) { int n = 4*(i % keyLen); int k = (key & (0xF << n)) >> n; result |= value&(0xF << 4...

Problem using regex to extract text

Hello! I need to extract from the following lines of code <label for="<%=foobar.bar %>">Password:</label> <label for="foobar">Password:</label> I need to extract foobar, I can use this: (?<=for=")[^"]+(?=(")) to extract: <%=foobar.bar %> and foobar but I don't want <%= or .bar and if I try to create (?<=for=")[^"]+(?=(")) | (?...

Is the ^ operator really the XOR operator in C#?

I read that the ^ operator is the logical xor operator in c#, but i also thought it was the "power of" operator. Can someone clear this up for me? ...

XORing at the address stored in EAX

How can you XOR the value stored in EAX? The problem is at this line: xor eax, key EAX contains the address of the value i want to XOR. How can I accomplish this? I though it would be something along the lines of: xor [eax], key but that doesn't work (syntax error) decrypt proc startAddress:DWORD , sizeOfSegment:DWORD , key:DWOR...

Java string to bytearray back to string

I have a client and server java application that needs have encrypted text passing through each other. I am using an XOR encryption the encrypt the text that I want. The problem is that readline() doesn't accept string that has been XORed and will only if accepted if it is in bytes. So I've converted my plaintext (string) into a byte a...