Math and
All Math
How Math
Helped Me
Lesson 1  Lesson 2  Lesson 3  Lesson 4  Lesson 5  Lesson 6  Lesson 7

Lesson 6 - Advanced Encoding Program

Note: To use the Javascript programs in these lessons, you will need to use a FireFox browser or other non-Internet Explorer browser due to the "feature" in the IE browser disallowing Javascript prompts.

This program does the following:

  1. Prompts you to input a letter. Then outputs the letter (to your screen). This is done for 8 letters.
  2. Assigns a variable to your letter.  For example, the first letter is assigned to the variable letter1a.
  3. Assigns each variable a value of 1 through 26, depending on what letter it equals where A = 1, B = 2, .....Y = 25, Z = 26.  So if letter1a = "C", then letter1a = 3.  If you enter something other than a letter A-through-Z or you enter nothing at all and hit the return, the variable is assigned to the value " * "
  4. Subtract each letter variable value from 27 using the formulas letter1a = 27 - letter1a, letter2b = 27 -letter1b, letter3c = 27 - letter3c, etc..  So if letter1a=3, 3 is subtracted from 27 and letter1a becomes equal to 24.  Then add 2 to this result to "bump up" the letter by two.  Also, apply modular arithmetic in base 26 to this result so that any result over 26 will be assigned to the remainder after dividing by 26. The resulting formulas for all 8 letters are:

    letter1a = (27 -letter1a + 2)%26;
    letter2b = (27 - letter2b + 2)%26;
    letter3c = (27 - letter3c + 2)%26;
    letter4d = (27 -letter4d + 2)%26;
    letter5e = (27 - letter5e + 2)%26;
    letter6f = (27 - letter6f + 2)%26;
    letter7g = (27 - letter7g + 2)%26;
    letter8h = (27 - letter8h + 2)%26;

    where the % symbol is used to invoke the modulus operation in Javascript code as was shown in Lesson 4.

    For the case of * corresponding to a space, an undefined value is calculated, which is not a problem since it ultimately gives you " * ".

    Note that I could have simplified this formula to letter1a = (29 - letter1a)%26 by adding 2 to 27..
  5. Assigns each new value back to a letter to produce a coded message.  So if letter1a is 5, letter1a is assigned the value becomes "E". Then outputs the letter. This is done for 8 letters. Note that if the letter variable was assigned a value of " *2 " or the new value is something other than a number from 1-to-26, it will output the value " * ". 
  6. Again, the code is programmed so any character with value ZERO is assigned to the letter "Z" in the final output.

To see the code used in this program, select View, Page Source in your browser's menu.

How Can I Quickly Decode Messages Made With This Code?
You can use this same encoder to decode messages.  Here's Why. The function used in this code example is equivalent to y = 27 - x + 2 and this simplifies to y = 29 - x. To reverse the operation of subtracting from 29, we simply subtract the result from 29 again. For example, if the original letter is "D", we get  29 - 4 = 25 which corresponds to "Y".  If we subtract 25, the number value of "Y" from 29, we get back 4 which indicates our original letter "D" again.

This Code Is Good, But Not Good Enough!
Unless one is looking specifically for the type of difference formula used in this code, they will not see any type of pattern. So to the casual observer, this is a very difficult code to break. But, if one has a computer program set up with many different deciphering algorithms, including one set up for various difference functions, they could crack this code in a matter of minutes. So to the person armed with some mathematical and computer skills, this code would be a piece of cake to crack.

Can We Use Different Formulas For Each Letter?
Yes, you can, provided that no two different letters are coded into the same letter. That task can be quite difficult and is another instance where a thorough knowledge of Abstract Algebra is essential. Such a code would be difficult to break.

Ready To Make Your Own Codes?
Go to Lesson 7 - Creating Your Own Secret Code!









Copyright 2021, Michael Sakowski and His Licensors
News on My Blog! Share Your Ideas! Copyright Info Suggested Uses Links Contact FAQs