0
votes

Im learning to create a java programme to encrypt and decrypt messages using Affine Cipher by following this tutorial

What im trying to understand is how to add in characters from 'a-z' and other characters like fullstops and commas and spaces to my programme.

What is the reason behind adding 'A' before encrypting?

static String encryptMessage(char[] msg)
{
    /// Cipher Text initially empty
    String cipher = "";
    for (int i = 0; i < msg.length; i++)
    {
        // Avoid space to be encrypted
        /* applying encryption formula ( a x + b ) mod m
        {here x is msg[i] and m is 26} and added 'A' to
        bring it in range of ascii alphabet[ 65-90 | A-Z ] */
        if (msg[i] != ' ')
        {
            cipher = cipher
                    + (char) ((((a * (msg[i] - 'A')) + b) % 26) + 'A');
        } else // else simply append space character
        {
            cipher += msg[i];
        }
    }
    return cipher;
}

I understand its got something to do with ASCII values but not sure what the reason is.

thanks!