cryptoHome Caesar Cipher

Background

A simple displacement cipher, apparently used by one of the many Caesars to send secret messages. It relies on a KEY (displacement) and rolling alphabet.

Remember, the original cipher used GREEK letters, apparently Julius always used the KEY of 3, making the subsequent decoding much simpler. It encrypts LETTERS only, spaces and punctuation remain unchanged.

Code

Cipher wheel from https://inventwithpython.com/cipherwheel/

Click wheel to rotate.

  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
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

Let's try it out:

Key:
Message:


Algorithm

BEGIN
  INPUT message
  UPCASE message
  INPUT key
  INPUT conversiontype

  INIT alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  INIT result = ''

  FOR each character in message
     IF character in alphabet THEN
        pos = position of character in alphabet
        IF conversiontype = 'encrypt' THEN
        	result = result + alphabet[(pos + key) mod 26]
        ELSEIF conversiontype = 'decrypt' THEN
        	result = result + alphabet[(pos - key) mod 26]
        ENDIF
     ELSE
        result = result + character
     ENDIF
  ENDFOR

  OUTPUT result
END