Showing posts with label Ciphers. Show all posts
Showing posts with label Ciphers. Show all posts

Sunday, 6 January 2013

Reverse Cipher Puzzle - Part 2

Looking at the formulae, you can see that in the subtraction we have, in the rightmost column, S - S = R, so R = 0 (zero). Going to the complex formula, you can see that subtracting O from TO gives a multiple of 10, so ignoring whatever T might be for the moment, (E + S) = 10. If you look at the addition, in the rightmost column, (S + O) = U (+ 10) (that is possibly 10). In the next column we have E + S, which we know is 10, so J is either zero or 1. It can't be zero because that's R, so it must be 1.

12345 67890
J R

Looking at the subtraction again, we've got another formula, (E - S) = T, the second column from the right. Using what we already know about E and S, we can say:

E - S = T
E - (10 - E) = T
2E - 10 = T
2E = T + 10
E = (T + 10) / 2

So for E to be a whole number, and a single digit, T must be even.

TES
264
473
682
891

T can't be 8 as S can't be 1 (it's J). In the subtraction, the third column from the right has T + E + 1 = U (+ 10), the 1 being carried over from (E + S). Plugging this into the table we get:

TESU
2649
47312 (or 2 + 10)
68215 (or 5 + 10)

Remember the first formula, (S + O) = U + 10, we got from the subtraction? We substitute 10 = (E + S) as before:

S + O = U + 10
S + O = U + S + E
(removing S each side)
O = U + E

Using this to get values for O:

TESUO
2649(6 + 9) = 15
4732(2 + 7) = 9
6825(5 + 8) = 13

O must be a single digit, so it can't be 15 or 13, leaving us with:

12345 67890
JUST EOR

Putting what we know into the addition, we get 374473 + 73F739 = 1113212 and making the obvious subtraction, 1113212 - 374473 = 738739, gives F = 8, leaving C and I.

Doing the same to the subtraction, 74873 - IC233 = 18C40, the third column from the right, 8 - 2 = 6, so C = 6 and I is 5:

12345 67890
JUSTI CEFOR

Which makes our formulae:

47737 * 65 = 3102905 374473 + 738739 = 1113212
74873 - 56233 = 18640 ((7 + 3) * 4) + 9 = 49

Friday, 4 January 2013

Reverse Cipher Puzzles

When I was a kid, there was a small book on codes and ciphers which got me interested in the whole thing. Normally, you would have a substitution cipher which substitutes numbers for letters, but the book had some puzzles which did it the other way around. For example, say you had the sum:

136732 + 643637 = 780369

You could replace the numbers with letters and try to figure out which letters stood for which numbers.

ACFGCB + FDCFCG = GHJCFI

Have a go at these:

TEESE * CI = SJRUORI SETTES + ESFESO = JJJSUJU
ETFES - ICUSS = JFCTR ((E + S) * T) + O = TO

All use the same substitutions.

Wednesday, 24 October 2012

Base64 Encoding

Although not strictly speaking a cipher (there's no encryption key), Base64 Encoding is important because it allows binary information to be transmitted as text, and so is frequently part of Internet protocols, notably MIME for e-mail. If you look at, say, an MP3 file in a hex editor, you can see the binary, represented in Hex (base 16):


What happens is that the binary data is broken up into from 8-bit bytes into 6-bit segments. These are then replaced by ASCII characters. In the following, the start of the second line in the above example is encoded.

Decimal57553272 10197
Hex (base 16)39372048 6561
Binary 00111001 00110111 00100000 01001000 01100101 01100001
Index 141928 32186 2133
Base64 EncodedOTcgS GVh

You can end up with a file looking something like this:

-----BEGIN PGP MESSAGE-----
Version: GnuPG v2.0.17 (MingW32)

lLtwfrsSgnpfUzopSdKcJjAfA1KE6SFTASBoH8JpnXV4AMrmMJVteTpeXr2nftHq
N8BUidauDqNvhKLADWWm5VhvnD7pkbNUv9nshW3SBT3jtmM/xxB3dNxeIfmSc78T
Z5jlEAjHVpS36KJNZSX+tn4fh8TDiTaw/yFOPxdZmwRXdN+fxAvao0/qq+dfsLQw
U5ELc/RavLf01iYwUrrdu97DUJwoLJIh/rxk2hdjgLY8cZRRexmGugb/tvojbq2L
EdOwa4d1gvDX/DYkYeOC4cCiACqwtTIk8IF+aqfrQ9BN2aVD0iuwm0QKqLsRNgxp
YMjtmF9T3UDmotfVsCNxx/HEaGwhU16VP+td9auMTVD124iQkeGFZfNMNynaeizp
bfRe5+OrzmyKVV/evQVlrHXag3RpG4UQx8yed/R+Ed7opd9KZgKT
=76xn
-----END PGP MESSAGE-----

Thursday, 19 August 2010

Ciphers

Running on from the previous article about codes, I thought I'd write some more, this time about ciphers.

A cipher differs from a code, in that a cipher replaces letters, or numbers, with another, whereas a code can replace many letters or words with just one. For example, the phrase "Meet me tonight" can be replaced by the code 1254, or "blue", or whatever. If we encypher the message, however, by replacing the individual letters with the key to the right on the keyboard we get "<rry ,r ypmohjy". This is known as a substitution cipher. The other type of cipher is called transposition. This is simply taking the letters of the message and re-arranging them, as in an anagram:

M M N T
E E I X
E T G Y
T O H Z

Reading the letters vertically produces the message, with a little extra letters to make a square number. Horizontally produces the code, MMNT EEIX ETGY TOHZ.

Digital Ciphers

Instead of working on letters of the alphabet, digital ciphers work on bits, or blocks of bits, usually using an XOR function. For example, convert the message to ASCII:

M e e t
m e
77 101 101 116 32 109 101
1001101 1100101 1100101 1110100 0100000 1101101 1100101

The XOR function changes the bits such that unequal bits produce a 1, while equal bits produce a 0. If we now use an ASCII key phrase:

Plaintext M e e t
m e
ASCII (Decimal) 77 101 101 116 32 109 101
Binary 1001101 1100101 1100101 1110100 0100000 1101101 1100101
Keytext S e n d
t h
ASCII (Decimal) 83 101 110 100 32 116 104
Binary 1010011 1100101 1101110 1100100 0100000 1110100 1101000
XOR Result 0011110 0000000 0001011 0010000 0000000 0011001 0001101
Decimal 30 0 11 16 0 25 13

The result of XORing is a series of mostly unprintable ASCII characters, but the stream now bears no relation to the original message. For example, the three "e"'s in the message are now all different, 0, 11, and 13.

The mechanism above is roughly how a Stream Cipher works. Instead of a key phrase, the cipher generates an endless stream of seemingly random bits which are XOR'd with the plaintext stream to produce the cipher stream.