[Cryptography] What is the difference between a code and a cipher?

Peter Fairbrother zenadsl6186 at zen.co.uk
Thu Sep 4 15:54:30 EDT 2014


On 04/09/14 19:42, Jerry Leichter wrote:
> On Sep 3, 2014, at 11:16 PM, Peter Fairbrother <zenadsl6186 at zen.co.uk> wrote:
>> Old chestnut - is it being intended to be hard to decrypt? Having a variable key? Something else?
>>
>> I don't know whether there is a definitive answer, but opinions are sought.
> Traditionally, codes operated at the word level, while ciphers operated at the character level.
>
> In the days of human encryption and decryption, codes relied on "dictionaries" that took a word to some specific sequence of symbols (in better codes, to one of a set of symbols to avoid leaking which sequences corresponded to common words), and symbols back to the word they came from.  The boundaries between words were as used in traditional grammar, and the boundaries between symbols were (necessarily) maintained.  Generally, punctuation was spelled out, so the input was really just words separated by spaces.  The encoding would usually just be groups of letters separated by spaces, too.  (Since the most common use of codes was in telegrams, the constraints of telegraphy would apply to the encoded form - and in practice would normally apply to the clear text as well.)
>
> Ciphers, conversely, transformed one character at a time.
>
> Encoding "sand" and "sandy" would produce two completely unrelated "code words".
>
> Enciphering "sand" and "sandy" would produce some four-character sequence for "sand", and that sequence followed by some fifth character for "sandy".
>
> The boundaries here were always somewhat arbitrary.  There were ciphers that operated on pairs of successive letters, for example.  (In principle you could have made the "block size" as long as you liked, but for paper-and-pencil operation more than two letters - which would likely be used to specify a row and column in an enciphering table - was probably the practical limit.)
>
> Codes in the traditional sense are no longer used.  (Actually, if I had to bet, they probably *are* still used in some specialized applications.)  The distinction is likely of historical interest only at this point.

I think we can agree what codes are, in modern terms.

Outside of cryptography, the concept of codes as reversible fixed 1:1 
mappings between an input set and an output set is used frequently - 
light is encoded as pixels, bits are encoded as pits in optical media or 
as magnetic domains on hard drives, grey codes, Morse code, and so on.

There are some partial exceptions like erasure codes, where the forward 
mapping is a semi-randomised injection rather than a bijection, and 
lossy codes as in .mp3 etc which are surjections, but idea of a fixed 
(in the sense of non-keyed) reversible mapping is pretty universal.

I don't think we can get around that modern usage of the word codes in 
crypto, and more, I don't think we should, or need to.



Defining ciphers in modern terms is a bit trickier.

In classical cryptography there were once codes, as exemplified in the 
code book in which an entry might be a word or phrase; and ciphers, 
which worked at the letter level, either substituting or rearranging the 
letters.

However in modern cryptography that classical concept of a cipher is no 
longer useful. The meaning of the word "cipher" is drifting, and I was 
really wondering how people use it today, rather than in 
historical/classical terms.



I think there was a drift towards "ciphers are meant to conceal 
information unless you have the key/code book", whereas codes might not 
be, and indeed nowadays are usually not, about concealment.



However, just speaking personally, nowadays I use "cipher" in technical 
discussions to mean a variable-keyed transformation which is supposed to 
be hard to reverse without the use of the key, and which is used to 
conceal information.

Yes, I also still use it in the classical sense in phrases like 
"monoalphabetic substitution cipher" when discussing classical crypto - 
but not when discussing modern crypto.

So to me the modern difference is, a cipher has a key, whereas a code 
does not. I think that's an actual quote, but I don't know who said it.



What I was really wondering is how widely other crypto people use the 
same modern definition?

Or what other definitions they use, in modern technical discussion?


I know NSA still use the word/letter distinction, but that's NSA. They 
do some things in a somewhat unusual and old-fashioned way.


-- Peter Fairbrother


More information about the cryptography mailing list