Rotation by n Encryption

Encryption

Caesar ciphers, and rotation.

Rotational encryption is the simplest and quickest method for encrypting a message, it is also one of, if not the, easiest to decrypt.

To encrypt a message, we first write down our standard alphabet, then below it, we rotate the alphabet by our desired encryption number, 13 for the ROT13 scheme, 3 for the Caesar cipher, or 1 for the Augustus cipher.

ROT13

abcdefghijklmnopqrstuvwxyz

mnopqrstuvwxyzabcdefghijkl

To encrypt the message

Rome has fallen

we begin matching letters from the top alphabet to the bottom one.

Our encrypted message now reads

Ebzr unf snyyra.


Julius Caesar used a simple rotation by 3 cipher for his messages, and his successor, Augustus used a simple rotation by one cipher. One can hardly get a feeling for the dearth of literacy during the Roman era.


To generalize these to an n cipher for the English alphabet, we must simply take n mod 26, use that shift, and write down our alphabets. From there, we simply shift away.


With the advent of computers, we can now use a multitude of computer languages to write such simple ciphers, here is some code in PHP.

Function rot($string, $enc)
{
for($i=0;$i {
$j=ord($string[$i]);
if ((($j>=ord("n")) & ($j<=ord("z"))) | ($j>=ord("N")) & ($j<=ord("Z")))
{
$j=$j-$enc;
}
elseif ((($j>=ord("a")) & ($j<=ord("m"))) | ($j>=ord("A")) & ($j<=ord("M")))
{
$j=$j+(26-$enc);
}
$new.=chr($j);
}
return($new);
}
?>

One notes that for n = 13, our n cipher becomes it own inverse, and we do not have to compute n mod 26 for encryption, and (26-n) mod 26 for decryption.

Your Ad Here