Did you know?


python caesar.py --key 1 --alphabet 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' --encrypt  --message 'Hello this is a test. Please enter your text here.' --keep-non-alp
Select a theme:


The Caesar cipher is named after the Roman military and political leader Gaius Julius Caesar (100 BC – 44 BC). Caesar used this relatively simple form of ciphering to encipher military messages.


The classic version uses the capital letters A-Z, but, in principle, an arbitrary alphabet can be used. The first step is to write the alphabet down two times.

A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z
A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z

Now, the bottom alphabet is shifted by an arbitrary number of positions. The number of positions is the value of the key. Shifting the bottom alphabet 3 positions to the right yields the following result:

A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z
D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z  A  B  C

The letter A becomes the letter D, B is replaced by E, and C replaced by F, etc. The word example would be enciphered to hadpsoh. The upper alphabet is called 'plaintext alphabet' and the lower alphabet is called 'ciphertext alphabet'.


The number of possible keys is identical to the size of the given alphabet. Using the capital letters A-Z as alphabet allows 26 different keys, with the 26th key rendered meaningless because it would map each letter to itself. With only 25 meaningful keys, it would be quite easy to test for all possible keys until the correct one is found (brute-force analysis). The Caesar cipher can also easily be cracked with a frequency analysis.

Internal working of the local Python version

About the code

In this plugin you can control the encryption process in two ways:

  • via the GUI
  • via the command line arguments for the Python program

The Python code is executed purely locally in your browser, without the need to install a Python development environment and also without the Python code being executed somewhere in the cloud. The following parameters can be changed via the GUI:

  • the text to be entered
  • whether to encrypt or decrypt the entered text
  • the key
  • the alphabet
  • whether to keep characters not contained in the alphabet
  • whether the output text should be shown in blocks of five.

These GUI parameters are passed to the script as command line parameters. Changes in the GUI change the respective command line parameters.

The code is a simple implementation of the Caesar cipher in Python. Each input character is converted to upper case and then processed. During the encryption, the Latin alphabet is used. For each character in the encrypted text, it is determined whether the character can be found in the given alphabet. If the character is found in the alphabet, the new character is determined by using the key. In case an input character is not included in the alphabet, the character is taken over unchanged (for example special characters). If a check mark is placed in the 'Blocks of 5' checkbox the output is displayed in blocks of five.

About the editor and the Python runtime

The editor available on this page was implemented with CodeMirror[1], which is a versatile text editor for the Browser and is implemented in JavaScript. CodeMirror has a number of add-ons for different programming languages. Pyodide[2] is used to execute the Python code.

Pyodide brings the Python runtime environment via WebAssembly into the browser, together with NumPy, Pandas, Matplotlib, parts of SciPy and NetworkX. In the editor there is now an interpreter for Python 3.x. You can see which exact Python version is used by Pyodide – by adding the following statement to the code: print(sys.version)


[1] Codemirror: https://codemirror.net/