NAME: Caesar Substitutional Shift Cipher
CREATOR: n/a
PB AUTHOR: 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.
NOTES: 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: http://pbcrypto.com/view.php?algorithm=caesar
Viewing source from caesar.bas   638 bytes   Last modified Wed, 20 September 2006

#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

Back to The Archives