Caesar Substitutional Shift Cipher
Algorithm creator(s)
n/a
PB author(s)
Wayne Diamond
Description
One of the simplest and oldest ciphers known, the Substitutional Shift Cipher is best known for being used by Julius Caesar, who used a position shift of 3. It is fairly similar (and just as insecure) as an XOR substitution cipher. Although there are just 25 distinct ciphers that can be made from shifting the position of the alphabet, there are over 400,000,000,000,000,000,000,000,000 such rearrangements that can be made by changing the position of the letters of the alphabet.
Note
The traditional Caesar cipher has a cipher alphabet of only the 26 letters of the English alphabet. The source code presented here accommodates for all 256 characters of the ANSI character set.
Source
n/a
See also
n/a
Source Code
Download source code file caesar.bas (Right-click -> "Save as ...")
#COMPILE EXE 'PBCC
FUNCTION CaesarCipher(sPlaintext AS STRING, lShift AS LONG) AS STRING
ON ERROR RESUME NEXT
LOCAL I AS LONG, lTmp AS LONG, sOut AS STRING
FOR I = 1 TO LEN(sPlaintext)
lTmp = ASC(MID$(sPlaintext,I,1)) + lShift
IF lTmp > 255 THEN lTmp = lTmp - 255
sOut = sOut & CHR$(lTmp)
NEXT I
FUNCTION = sOut
END FUNCTION
FUNCTION PBMAIN() AS LONG
DIM Plaintext AS STRING, PosShift AS STRING
STDOUT "Plaintext string to encrypt: ";
STDIN LINE Plaintext
STDOUT "Position shift (1-255, Caesar used 3): ";
STDIN LINE PosShift
STDOUT "Encrypted: " & CaesarCipher(PlainText, VAL(PosShift))
WAITKEY$
END FUNCTION