1
$\begingroup$

I have an upcoming exam where I can use a simple Calculator. On some sample questions they ask us to XOR two values (for AES round key) and I know how to write it out by hand but is there any other faster way as the exam is timed of course.

$\endgroup$
9
$\begingroup$

If you are lucky, the definition of "simple calculator" may include all non-graphic calculators. In that case, you can use a Casio FX-115ES Plus, which includes hexadecimal and octal base modes, and has an XOR operator. It can operate on groups of octets up to 32 bits.

If you are not that lucky, the XOR table is your best friend. Depending on how many calculations you need to perform, it may very well be faster to create one on a scratch sheet during the exam. You may even be allowed to bring one with you.

XOR Table 0

I had a requirement for an XOR table to perform quick calculations on a printed code book for cryptographically strong communication over a public voice channel. It also had to be done quickly without the use of a computer or any electronic device, and had to fit on a small 4x6 sheet in the space under the ciphertext.

I came up with several methods to condense the table and still have it usable. If you are clever and resourceful, the knowledge of how to create the condensed versions can allow you to very quickly perform many XOR calculations. There is a recursive pattern to the hexadecimal XOR table which can be exploited, the table above is color coded to show this pattern, which extends down to the individual characters. Here are the condensed tables:

XOR Table 1

While the above table takes up less space, it has the same amount of characters, and thus takes about the same amount of time to create. A simple rule is required to select the correct characters.

XOR Table 2

The next level now takes both half the space of the previous, as well as half the characters. The rule is more complex, but a few minutes of practice makes it almost as fast to use as the full table. Even the rule can be simplified with XOR, the result will be correct if the XOR of the rule selections is 1.

XOR Table 3

The final level is once again half the space and half the characters (almost) as the previous, while requiring an additional rule to get the job done. If you remember the recursive structure and the basic layout of this table, you can recreate it in under a minute with a pen and paper.

Start with the inner column header, first nibble; 0 1 2 3 4 5 6 7
Then add the 2nd nibble, which is the first nibble + 8; 8 9 A B C D E F
The outer column header is the inner column header with the halves flipped
The inner row header is the first half of the inner col header
The outer row header is the first half of the outer col header
Then you fill in the table with the recursive structure, built from the inner column header.
Creating the double compressed table omits the outer headers but uses a full row header.

A single example on the triple table:

25 XOR B6
2 X B = [2a] X [3b] (1 2 2) = 9
Because 2 is the 1st nibble and B is the 2nd, we use the 2nd nibble of [19]
5 X 6 = [5d] x [6e] (1 1 1) = 3
Because 5 is the 1st nibble and 6 is the 1st, we use the 1st nibble of [3b]
Therefore 25 XOR B6 = 93

$\endgroup$
3
$\begingroup$

Try converting hexadecimal numbers to binary numbers and perform exclusive ORs on each and every bit. Then convert the binary numbers back to hexadecimal numbers.

$\endgroup$
  • 1
    $\begingroup$ Furthermore, since 16 is exactly 2^4, you can do this digitwise. That is, you don't have to convert the whole number to binary at once, you can do it one digit at a time, xor, then convert the result back to hex $\endgroup$ – Cruncher Jan 23 '17 at 8:35
1
$\begingroup$

xoring 2 bits is easy.
converting a hex digit to 4 bits is easy.

The combination of these 2 facts should make xoring a single hex digit pretty easy. If you write down a table for each digit to binary(in a timed test, whether this is worth it or not depends on the number of conversions you'll have to do), you won't have to do any written calculation really. For example to xor e and 3, is 1110 xor 0011 which is 1101 which is d. If you have a table ready this calculation is basically instant.

Now just repeat this for all digits. This can be done digit wise as each hex digit resents exactly 4 bits

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.