Encryption Basics
The other day I was talking to free downloading of adobe addition 2.0 a friend of mine who is an art major. One way or free downloading of adobe addition 2.0 another the topic of encryption came up. How I managed that free downloading of adobe addition 2.0 is another story. This article, as I hope, will serve as an free downloading of adobe addition 2.0 introduction to non-majors who has absolutely no exposure to this kind of materials.
Motivations
When datas are free downloading of adobe addition 2.0 transmitted, most commonly over the internet or any large networks, it free downloading of adobe addition 2.0 likely that the information will be seen by unintended parties. This is free downloading of adobe addition 2.0 not a desirable effect but at the same time unavoidable without tremendous cost. To answer the free downloading of adobe addition 2.0 need for confidentiality of data transmitting over networks we “encrypt” the data before transmitting.
Again..
Imagine networks as the free downloading of adobe addition 2.0 roads. Any entity can stand on the side of public roads and free downloading of adobe addition 2.0 observe the traffic on it, see what being transmitted, count how many cars (packets) of each type, when the road is busiest such and such.. Now our main characters here are free downloading of adobe addition 2.0 Alice and Bob, they have the need to communicate constantly and free downloading of adobe addition 2.0 privately. To avoid people seeing her messages when free downloading of adobe addition 2.0 using the public road Alice can build a road from her place directly to free downloading of adobe addition 2.0 Bob. This way any items sent from her to bob will be free downloading of adobe addition 2.0 carried on this private road that no one else has access too. This would be free downloading of adobe addition 2.0 much more secure and preferrable than using the public road, if not for free downloading of adobe addition 2.0 the extra cost. Even worse when Alice now want to send messages to free downloading of adobe addition 2.0 Cooper also. We can see building private roads for each entity you free downloading of adobe addition 2.0 would like to communicate with is not a valid solution.
Reason Alice didn’t want to free downloading of adobe addition 2.0 use the public roads is because people can read her message. Now if she can free downloading of adobe addition 2.0 somehow send something totally unintelligible to Bob, then she wouldn’t mind people reading it. However at the free downloading of adobe addition 2.0 receiving end, bob, through some procedures, must be able to free downloading of adobe addition 2.0 turn the encrypted message back into something meaningful. If they can free downloading of adobe addition 2.0 do this then she can use the public road as much as she wants since she is free downloading of adobe addition 2.0 not afraid of people seeing what she is sending (because they wouldn’t understand). That is the very basic of encryption
The Shift Cipher:
I’ll introduce to free downloading of adobe addition 2.0 you the Caesar Cipher, or Shift cipher. It works as follow. Each letter in the free downloading of adobe addition 2.0 plain text will be replaced with another letter a few places away from free downloading of adobe addition 2.0 it in the alphabet.
For example:
A -> C
B -> D
C -> E
D -> F
E -> G
F -> H
G -> I
H -> J
…X -> Z
Y -> A
Z -> B
and so on.
Thus to send
HELLO THERE
you would send:
JGNNQ VJGTG
Here every letter is free downloading of adobe addition 2.0 changed to the letter 2 places after it in the free downloading of adobe addition 2.0 alphabet. For this cipher if you know the key k=2 you can encrypt message AND also decrypt (just move letters back 2 spaces). It is free downloading of adobe addition 2.0 obvious that such a method is very insecure because there are free downloading of adobe addition 2.0 only 26 possible keys. With little computational power one can easily attempt to free downloading of adobe addition 2.0 decrypt with all 26 keys and will find one that is free downloading of adobe addition 2.0 the correct key (this is the bruteforce attack).
But if no one know the key, then the ciphertext (the text created after the encryption process) would look totally unintelligible to free downloading of adobe addition 2.0 a 3rd party and the communication is confidential.
And that is the very basic of data encryption.
Modulo 26
When encrypt and free downloading of adobe addition 2.0 decrypt messages it is natural that we assign numbers to letters in the free downloading of adobe addition 2.0 alphabet. ‘A’ would be 0 (zero), ‘B’ is 1, ‘C’ is 2, … , and ‘Z’ is 25. Now when shifting with key = 2. ‘Z’ will be shifted by 2 so it would be 25+2 = 27. But this wouldn’t make sense since we only have 26 letters (would need 28 characters to address the value 27). It is natural to apply modulo 26 to ‘Z’ =25 to give 1, or ‘B’.
we write
27 = 1 (mod 26)
26 here is called the modulo. “27 mod 26″ simply is free downloading of adobe addition 2.0 the remainder you have after you divide the modulo into 27.
As you could imagine
27 = 2 (mod 25)
Brute-force (slowest) to find x mod n is free downloading of adobe addition 2.0 to repeatedly subtract n from x until you get to free downloading of adobe addition 2.0 a value that is smaller than n. Of course if x < n then x mod n is just x. Also n mod n = 0 for all valid n.
In C++ you can use the % operator to free downloading of adobe addition 2.0 find remainder, however it does not always return a positive result. This is free downloading of adobe addition 2.0 a simple implementation of the modulo function:
int mod(int x, int n)
{
if (0==n) return -1;
if (x<0) return (x+(-1)*(x/n)*n+n);
if (x<n) return x;
else
return x-(x/n)*n;
}