Affine Cipher / Encode Mod 26

Encoding to Integers Modulo 26

To work with the affine cipher, and many other ciphers, we need to convert strings to lists of integers modulo $26$. In the next cell, I show how to do this with the use of a for loop. The for loop directs Sage to step through each character in the string and turn it into an integer modulo 26. Then it collects these in a list, called encodedString.


Encrypting with Affine Cipher

Choose an alpha and beta in $R$.


Decrypting with Affine Cipher

For this, we need to use $\alpha^{-1}$, but we can ask Sage to compute it for us.


Decoding from Integers Modulo 26 to Text

For this, we use another for loop: