Ä Fido Pascal Conference ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PASCAL Ä Msg : 362 of 384 From : Steve Connet 1:300/15.0 26 May 93 10:43 To : Rob Perelman Subj : Encryption Alg. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Hello Rob, RP> > Password[i] := Char(Ord(Password[i]) XOR i) RP>Can you tell me what XOR does? XOR stands for Exclusive Or. Here is the Truth Table for XOR: 0 xor 0 = 0 0 xor 1 = 1 1 xor 0 = 1 1 xor 1 = 0 Here is how it works: Say I have the string "ABC". Here is a table showing the letters, their ascii value, and their binary value. (We will work with the binary value). LETTER ASCII BINARY ------ ----- --------- A 65 0100 0001 B 66 0100 0010 C 67 0100 0011 Here is the encryption snippet again: For i := 1 to ord(Password[0]) do Password[i] := Char(Ord(Password[i]) XOR i) If you follow this snippet, you'll see that the first element of the string is being xored by the position of the element (ie. XOR i). For example, 'ABC' would be xored like this: A xor 1 B xor 2 C xor 3 That way the the right side of the xor is always changing, and thus hard to decrypt manually. If the right side of the xor was, say, always 255, every element of the string would be xored by 255 and a hacker could figure it out. If the right side is always changing, it is much harder to figure out. So let's take a look at what happens when we use our snippet with the string 'ABC'. LETTER ASCII BINARY (this shows us how it works) (A xor 1) = (65 xor 1) = (0100 0001 xor 1) (B xor 2) = (66 xor 2) = (0100 0010 xor 2) (C xor 3) = (67 xor 3) = (0100 0011 xor 3) Remember the truth table concerning XOR above? Let's look at the binary equivalent of our 'ABC' string. A B C Truth table ------------- ------------- ------------- -------------- 0100 0001 xor 0100 0010 xor 0100 0011 xor 0 xor 0 = 0 0000 0001 0000 0010 0000 0011 0 xor 1 = 1 ========= ========= ========= 1 xor 0 = 1 0100 0000 0100 0000 0100 0000 1 xor 1 = 0 Using our snippet, the resulting value for EACH element of the string 'ABC' is, surprisingly, 0100 0000 (which equals 64 decimal) which is the character '@'. So the resulting value of the string 'ABC' when XORed with our snippet is the new string '@@@'. So 'ABC' encrypted with our snippet becomes '@@@'. How is it possible at all for a hacker to get 'ABC' out of '@@@'??? So you see, our snippet works quite well. To decrypt the string, just send it right back through our snippet. So if you stick '@@@' in our snippet ... 'ABC' will be the resulting value. Pretty neat eh?