# Using simple linear algebra for encryption?

e.g. the character $a = 97$ (it's computer decimal format, commonly known)

and then using a pattern/key like $y = 31 x + 5$ to get $3012$ (substitute $97$ into $x, y$ is now the encrypted code).

1. How easy/hard would it be for someone to crack a code like this? 3012 3197 3135 (without them knowing the pattern)

2. If someone had these encrypted codes, are there any methods they could use besides trial and error to figure out the pattern and then the code?

-
Knowing the code had this format, quite easy. But more importantly, for something like this to be useful, you need to communicate the encryption to the sender, and in this case, knowing how to encrypt allows you to decrypt just as easily. –  Tobias Kildetoft Jul 9 '13 at 13:32
what if the only person reading it and the only person that knew the pattern was yourself, and the only reason to encrypt it was so that you could store this info in the cloud? –  mike.h Jul 9 '13 at 13:36

## 2 Answers

What you have described is nothing more than a single-alphabet substitution cipher. This sort of cipher has been around for centuries, with variations on the type of mapping. It is very easy/simple to break if given enough ciphertext encoded with the method.

To break this cipher, first analyze the frequency of the resulting numbers. (e.g. 3012 occurs what percent of the time in the message?) Now, compare this to a frequency table of letters in the English alphabet. This will give you a starting place. You can also look at the frequency of pairs of letters. By that time, you should have a pretty good guess for the substitutions.

-
this reply lead to some very interesting reading on wikipedia, thanks. –  mike.h Jul 9 '13 at 14:02
What if you made the encryption formula $31x+p \mod n$ where $p$ is the encrypted value of the preceding character and $n$ is a pre-agreed value to keep the numbers small? At least then the 'a's won't all get encrypted to the same value and so frequency analysis won't work. –  Peter Phipps Jul 9 '13 at 14:04
@PeterPhipps: Congratulations! You've invented a version of the Vigenere cypher. It's a bit harder to break than a substitution cypher, but still far from secure. –  Rick Decker Jul 9 '13 at 14:30
@user2552685 Glad to help! :) If you're interested in codes/ciphers, may I suggest "The Code Book" by Simon Singh. It's not a textbook (so it's pretty easy to read), and it talks about different types of ciphers from all periods of history (and how they have been broken down). It also talks about modern methods (e.g. RSA), and talks about the possibility (and effects) of quantum cryptography at the very end. It's a great read, and it has some ciphertext at the back of the book to decode. I really enjoyed it. –  apnorton Jul 9 '13 at 14:38
@PeterPhipps: How would you decrypt the code after using modulus? –  mike.h Jul 9 '13 at 15:42

If you put the spaces in, it is quite easy. You wouldn't have to find $31x+5$, as there will only be $26$ (or $52$ or so if you use caps and punctuation) four digit blocks. Just checking letter frequencies will make it easy to find $3102=a$ and so on. It is like solving the substitution cypher in the daily newspaper.

If you don't put the spaces in, it will be a little harder. A bit of creativity would find that the four digit blocks repeat. Thinking in this direction, the $31x+5$ is probably easiir to see, but you could proceed as above.

-
i never tried the cipher puzzles in the newspapers before, good answer thanks –  mike.h Jul 9 '13 at 14:07
Note that the ones in the paper are often constructed to not have the usual letter distribution. There may be no e's, for example. But if you see qrjq it is probably that or high, for example. There are many patterns in natural language text that can be exploited to break a cypher. Any good crypto system needs to destroy them. That is one reason they tend to translate the message into one or more large numbers, then operate on them. –  Ross Millikan Jul 9 '13 at 14:46