CG3.5 Logical Operations You need to understand: • Draw truth tables for the AND, OR, NOT and XOR logical operations. • Apply these logical operations to combinations of conditions in programming and package use, in masking, in control systems and the use of XOR in encryption. A truth table shows how a logic circuit's output responds to various combinations of the inputs, using logic 1 for true and logic 0 for false. We know this is how computers encoding information. You have used the AND, OR, NOT operations in programming, some may also have used the XOR operation. Truth tables: AND: OR: XOR: A B Output A B Output A B Output 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1 0 1 1 0 1 1 1 1 1 1 1 1 1 0 Masking A mask defines which bits you want to keep, and which bits you want to clear in a bit pattern. Say you are only interested in the 4 most left bits in a 8-‐bit pattern “10110101”, you apply a mask of “11110000” using AND operation. Since “0” AND with any bits “0” or “1” results in “0”, this effectively gets ride of the last 4 bits and leave the first 4 bits intact. Here is an example of getting the last four bits by using AND: Mask: 0000 1111 Value: 0101 0101 Result: 0000 0101 If the last 4 bits of the last bit pattern needs to be flipped (“0” to “1” or “1” to “0”), you can apply a mask of the same “0000 1111” but use XOR: Mask: 0000 1111 Value: 0101 0101 Result: 0000 1010 Using XOR in Encryption This encryption technique uses a simple fact that any bit pattern XOR with itself, it result in all zeros. It works in the following way: To encrypt: BitPattern XOR Encryptionkey = encryptedBitPattern To decrypt: encryptedBitPattern XOR Encryptionkey = BitPattern So if you and the message sender share the same encryption key, then you can communicate “secretively”. Here is an example: Encrypt: Original data: 1001 0110 Key : 1010 1101 XOR result: 0011 1011 (the encrypted data) Decrypt: Key : 1010 1101 Encrypted data: 0011 1011 XOR result: 1001 0110 (the original data) Exam questions: 2012S. Q10 A computer system uses the exclusive OR (XOR) logical operator to encrypt data before it is transmitted along a network. Draw the truth table for the XOR logical operator and use a worked example (using 8 bits) to demonstrate how data is encrypted using this method, including how the original data is decrypted. [3] 2010W.Q5 (a) Write down the truth table for the EXCLUSIVE OR (XOR) operation. (b) Two eight-bit numbers are: X 10011011 Key 11010111 Include these two numbers in a worked example to explain how the XOR operation can be used for encrypting data. You should also show how the original data can be recovered.
© Copyright 2026 Paperzz