Cryptography (1–5 Levels)


XOR Encryption(Internal Working){LEVEL 4}



Yüklə 1,44 Mb.
səhifə5/8
tarix06.10.2023
ölçüsü1,44 Mb.
#152584
1   2   3   4   5   6   7   8
shehro\'z

XOR Encryption(Internal Working){LEVEL 4}:
Before i start, congrats you’ve made it so far, i would like to thank Mukul Sir who around a year back, taught few of the lucky ones what XOR gates and how they work. I have since many books on XOR and took me some time to understand it.
Introduction to classical Electronics:
Well computer are not that smart, they can only understand 2 operations, in programming we call this boolean operator or TRUE/FALSE operators. Computers work on binary, ie 0 and 1. where 1 represents true and 0 represents false. Through total of 7 gates or operations, every single task on a computer is performed, they are AND, OR, XOR, NOT, NAND, NOR, and XNOR respectively.
Let’s eat only what we can swallow as discuss about XOR:
XOR and TRUTH TABLES:
“XOR” an abbreviation for “Exclusively-OR.” The simplest XOR gate is a two-input digital circuit that outputs a logical “1” if the two input values differ, i.e., its output is a logical “1” if either of its inputs are 1, but not at the same time (exclusively). The symbol and truth table for an XOR is shown below. The Boolean expression for a two-input XOR gate, with inputs A and B and output X:
To simplify, you pass two arguments(Plaintext in binary and key in binary) and if they both are identical then following the rules of the truth table, the output will be given. If both are the same we write “0” and if they are different we write “1”. Pretty simple? Go and Learn about the 6 remaining.
XOR implementation in XOR encryption:
Now that we have learnt about XOR, lets talk about encryption with it, here how we implement it. As previously discussed, XOR can only take in binary but you might not know how its done, so let me walk you through. (SKIP if you’re from ISC/ICSE)
Every key you use on your keyboard has two notation, one is the notation you use and another one is ASCII:
How does ASCII work? Pretty simple, look at the table, you know that the English alphabet has 26 letters which makes up all words you speak in English. In ASCII the representation of alphabets begins from 65, why? Because there are other stuff in your computers which i will not discuss here. To conclude, “A” = 65 in ASCII, B is “66” and Z is “90”, note the upper case.

USEFUL CHARTS THAT YOU WON’T READ
So now that's clear but how do we get it to binary? well the logic is pretty simple, suppose you want to convert “A” to binary to perform XOR encryption, to convert, you can simply see that A = 65. We can now convert 65 into binary. If you don’t know how to do that well ill teach you:
There are two ways, one is with Maths and another one is without maths.
Lets do without maths for today:
A = 65
Now first we set up a table, the table has increasing two raise to the power. Since its binary. Now taking the character A = 65, we can put it in the following table. 65–128= would make a negative thus we reject it. We go with 65–64 = 1 since we can completely subtract, we allow write a 1 at 64 denoting true or success. Now remainder 1 cannot be subtracted by 32,16,8,4,2 since its smaller thus we write 00000 denoting false, or unsuccessful, lastly 1–1=0, since we can subtract and not get a negative result we write TRUE = 1
PROTIP: You cannot subtract and get negative. 1=true and 0 = false
Thus our chart looks like:
128 = 0
64 = 1
32=0
16=0
8=0
4=0
2=0
1=1
Thus if you write it in one line we get 1000001, note we do not write 0 at first.
Now you know the background logic, feel free to boast this. Here’s a simple program i wrote back in class 8 in java to convert characters to ascii. This logic is called explicit typecasting. Pick up a Sumita Arora and get these concepts cleared.

Now we take a random binary key and XOR it with the character “z=122”, lets try it out with z. Following the truth tables, this will be a piece of cake. Now this key we are talking about is Pseudo Randomly generated ie, unknown so XORing both will give us a binary output.
Practical: XORing z=122 = 01111010 with Key 01010101

There is a problem here, you guessed it. If the key gets leaked then one can decrypt the message and that is the essence of cryptography.

Yüklə 1,44 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin