python caesar.py --key 1 --alphabet 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' --encrypt --message 'Hello this is a test. Please enter your text here.' --keep-non-alp
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 key-value. 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 encipher by: „hadpsoh“. The upper alphabet is called 'plaintext-alphabet', 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.
● Caesar-Code: https://en.wikipedia.org/wiki/Caesar_cipher
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, but also without, that the Python code must be 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 characters not contained in the alphabet should be kept
- whether the output text should be output in blocks of five.
These GUI parameters are passed to the script on the command line. Changes in the GUI change the respective command line parameters.
The code is a simple implementation of the Caesar encryption 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 key is used to find the new character is determined. 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
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).