Difference between revisions of "Cryptography"

From Game Detectives Wiki
Jump to: navigation, search
[unchecked revision][unchecked revision]
m (Basic Ciphers)
m
Line 32: Line 32:
 
and the resultant ciphertext would be <code>Icog Fgvgevkxgu</code>.  To decrypt this string back into <code>Game Detectives</code>, 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)''
 
and the resultant ciphertext would be <code>Icog Fgvgevkxgu</code>.  To decrypt this string back into <code>Game Detectives</code>, 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)''
  
=== Hex cipher ===
+
=== Binary ciphers ===
  
The Hex cipher, and other variants (such as Octal, Decimal, and Base64), rely on the fact that each ASCII character that you can type has a unique identifying number.  For example,
+
'''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 number, in binary.  For example,
 +
 
 +
* Uppercase <code>A</code> has a binary code of <code>01000001</code> (converting to <code>65</code> in decimal)
 +
* Lowercase <code>a</code> has a binary code of <code>01100001</code> (converting to <code>97</code> in decimal)
 +
* Ampersand <code>&</code> has a binary code of <code>00100110</code> (converting to <code>38</code> in decimal)
 +
* Plus sign <code>+</code> has a binary code of <code>00101011</code> (converting to <code>43</code> in decimal)

Revision as of 16:11, 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 ciphers

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 number, in binary. For example,

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