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

John Denker jsd at av8n.com
Fri Sep 5 14:27:46 EDT 2014


In classical cryptology, "code" more-or-less refers to looking 
stuff up in a codebook.
 -- This is not necessarily a 1-to-1 mapping;  good-quality
  codebooks have had homophones for hundreds of years.
 -- This is not limited /solely/ to encoding of words, phrases,
  and other high-level linguistic and semantic units.  Any
  decent codebook will have codes for individual letters, 
  although these should be used sparingly.
 -- Codewords (codegroups) need not have fixed length.
 -- Not every code is a secret code.  A good codebook can
  provide treeeemendous compression, which is a sufficient
  reason to use it, even if secrecy is not required.

The classical definitions are set forth in detail starting on
page xv in the preface to David Kahn's book _The Codebreakers_

Etymologically speaking, the term codebook is redundant;  originally 
to codify something meant to write it into a book, i.e. a codex.
Example:  United States Code i.e. the book of laws.

=============

Meanwhile, if we widen the focus to include things other than
cryptology, the word "code" has a much broader meaning.  Almost
any system whereby one thing symbolizes another is called a code.

On 09/04/2014 04:14 PM, Bill Frantz wrote:
> 
> It seems to me that "code" is short for "encoding". In ham radio we
> are not permitted to try to obscure the meaning of transmissions, but
> we can and do use a large number of codes. We have lots of examples
> of codes which are not intended to provide secrecy. Examples from ham
> radio are Morse code, ASCII code, Baudot code, and Varicode. Other
> codes attempt to reduce the length of information. The ham radio "Q"
> codes perform this role and have the added advantage of allowing
> people who do not speak a common language to communicate. For
> example, QTH? means, "What it your location?"

Agreed.

Various fields of endeavor have codes including
  data compression:     Lempel-Ziv code;  Huffman code; ....
  computing:            hash code;  PDP-8 machine code;  c++ code; ....
  error correction:     phonetic alphabet (alpha bravo charlie ...);
                        Reed-Solomon code; ....
  data representation:  NTSC;  ATSC;  GSM half-rate voice codec;
                        QAM-64 code;  FM;  NRZ code;  ASCII code;
                        Morse code;  Braille;  semaphore flags ....

These things can be layered:  A cable operator might send ATSC
over QAM-64.

More specialized fields can have their own codes:

 -- "Lifeguard seven seven charlie, Seattle Center roger, Boeing
  altimeter two niner niner zero, squawk four zero zero one,
  cruise seven thousand."

  If you don't know the code, you might have a hard time guessing
  what that means.

 -- Q-codes.  European aviation uses QNH and QNE.  The US uses
  the same concepts, but names them differently.

 -- The APCO 10-codes are deprecated, but are still used.

Note that in popular culture, many codewords including "10-4" 
and "roger" are very often used incorrectly.  People think they 
know what these codewords mean, but they get it wrong.

Also in popular culture, the word "code" sometimes connotes
"secret code".  This is something to beware of when speaking
to non-experts.

Some codes provide compression, while others actually expand 
the length of the message (typically to provide error
correction).  The compression factor is well-defined when the
input and output media are the same, such as compressing one
file to make another.  However, when switching media, all you
can do is compare one code to another.  If you didn't encode
the bits in QAM-64 or something similar, you wouldn't be able
to put them on the wire at all, so the notion of compression
ratio fails the dimensional-analysis test.  However you can
say that QAM-64 gives considerable compression relative to FSK.

==============

A one-time codebook is as secure as secure can be, just like
any other one-time pad.

Enciphered code is typically more secure than either straight
code or straight cipher.  That's because there is less entropy 
density in the codetext than in the original plaintext.

=================================

To answer the original question:  The definition of cipher
overlaps with the definition of code, insofar as a simple
substitution cipher (such as "the dancing men") is both a
code and a cipher.


More information about the cryptography mailing list