Difference between revisions of "Cryptography"

From Game Detectives Wiki
Jump to: navigation, search
[unchecked revision][unchecked revision]
m (Binary cipher)
m (Binary cipher)
Line 34: Line 34:
 
=== Binary cipher ===
 
=== Binary cipher ===
  
To experiment with the binary cipher, click [http://www.binaryhexconverter.com/binary-to-ascii-text-converter here].
+
''Click [http://www.binaryhexconverter.com/binary-to-ascii-text-converter here] to experiment with the binary cipher.''
  
 
'''What is binary?'''
 
'''What is binary?'''

Revision as of 16:20, 26 August 2016

Cryptography is the process of hiding messages; either by concealing them (eg. hiding them in an image), or by obfuscating them outright (eg. substitution cipher).

Basic Terminology

  • Cipher: a method of encryption
  • Plaintext: the legible text of a hidden message
  • Ciphertext: the text after a message is concealed in it
  • Encryption: The process of turning plaintext into ciphertext
  • Decryption: The process of converting ciphertext back into plaintext
  • Key: a string used in the encryption and decryption processes of some ciphers, akin to a password

Basic Ciphers

Caesar cipher

Click here to experiment with the Caesar cipher.

The simplest example of a cipher is the Caesar cipher. The rules of the cipher are as follows:

Let n equal a value from 1 to 25
Shift each letter in the plaintext forward by n positions in the alphabet
The resultant string is the ciphertext

For example, to encrypt the string Game Detectives using the Caesar cipher, using an arbitrary n value of 2, then:

G -> H -> I
a -> b -> c
m -> n -> o
e -> f -> g
...

and the resultant ciphertext would be Icog Fgvgevkxgu. To decrypt this string back into Game Detectives, the process can simply be reversed by shifting each letter of the ciphertext 2 places backwards. (Note: another common name for the Caesar cipher is ROT<n> - ROT13 indicates that each letter is shifted halfway through the alphabet)

Binary cipher

Click here to experiment with the binary cipher.

What is binary?

Binary is a system of counting, used by computers, that is different than the typical system of counting. You're used to counting by using 10 different digits: 0 to 9. This is known as base 10, or decimal. Binary only uses 2 digits: 0 and 1, so it is known as base 2. Let me give you an example.

This is how you write the number one hundred and nine normally, in base-10. The top row represents the values of each digit place; you can see that, starting from the right-hand side and moving left, each consecutive decimal place is worth 10 times more than the previous one in base 10. The bottom row can use digits from 0 to 9.

+-----+-----+-----+
| 100 | 10  |  1  |
+-----+-----+-----+
|  1  |  0  |  9  |
+-----+-----+-----+
1*100 + 0*10 + 9*1
= 100 + 0 + 9
= 109

Okay, now, here's how you write the same number, one hundred and nine, in base-2. Again, the top row represents the values of each digit place; but this time, each decimal place is only worth 2 times more than the previous one in base 2. Now, the bottom row can only use the digits 0 and 1.

+-----+-----+-----+-----+-----+-----+-----+-----+
| 128 | 64  | 32  | 16  |  8  |  4  |  2  |  1  |
+-----+-----+-----+-----+-----+-----+-----+-----+
|  0  |  1  |  1  |  0  |  1  |  1  |  0  |  1  |
+-----+-----+-----+-----+-----+-----+-----+-----+
0*128 + 1*64 + 1*32 + 0*16 + 1*8 + 1*4 + 0*2 + 1*1
= 0 + 64 + 32 + 0 + 8 + 4 + 0 + 1
= 109

So, the base-10 (decimal) number of 109 is equal to the base-2 (binary) number of 01101101.

How is binary used in a cipher?

The binary cipher relies on the fact that each ASCII character that you can type on your keyboard has a unique identifying code, in binary. For example,

  • Uppercase A has a ASCII code, in binary, of 01000001 (converting to 65 in decimal)
  • Lowercase a has a ASCII code, in binary, of 01100001 (converting to 97 in decimal)
  • Ampersand & has a ASCII code, in binary, of 00100110 (converting to 38 in decimal)
  • Plus sign + has a ASCII code, in binary, of 00101011 (converting to 43 in decimal)

So, all that is required to encrypt a binary cipher is to convert the ASCII characters into their codes - and to decrypt the cipher, the codes are changed into the characters. For instance, encoding the string Game Detectives would give you:

+-------+--------+
| ASCII | Binary |
+-------+--------+
|   G   |01000111|
|   a   |01100001|
|   m   |01101101|
|   e   |01100101|
|  and so on...  |
+-------+--------+
01000111 01100001 01101101 01100101 00100000 01000100 01100101 01110100 01100101 01100011 01110100 01101001 01110110 01100101 01110011