Hi, i need to change every letter from the word that was entered into its 3rd "neighbour" in ABC. E.G., word "GRAMMAR" would be executed as "JUDPPDU". The problem is that in some places of an executed word i get characters instead of a latin letter. I have to use only simple equations, basically, no constant functions for conversion or etc., because im only a beginner.
If you want to read more about what Kemort used google "Caesar Cipher", Offsetting by 3 is like having a cipher of each letter + 3
The algorithm a caesar cipher is:
Ciphertext = (Plaintext + Key) % 26
The problem with coding it is that: It assumes character values 0-25, a-z.
Let c = plaintext
c = 'G';
c = (c + 3) % 26
We will receive a result of 22, Which is not 'J'
Well okay, Lets add the Char value 'A' to try to get a char value.
c = 'A' + (c + 3) % 26
65 + (71 + 3) % 26
65 + 22 //74 mod 26 is 22
We will receive a result of 87, Which is 'W' not 'J'
Darn okay. Well J is only a value of 9 From A. So lets get the parenthesis to equal 9.
To do that we see that we ask what value can be subtracted from 71 to equal 6. (We already know we have to add 3)
71 - 65(the value of 'A') will give us 6... plus the 3 we already need to shift... 9!
c = 'A' + (c - 'A' + 3) % 26
65 + (71 - 65 + 3) % 26
65 + (6 + 3) % 26
65 + 9 % 26 //9 modulo 26 is 9.
=74
74 is the value of 'J'!
An alternative is to set A-Z to 0-25, This can be easily accomplished by throwing them in a string and using Findfirstof to find the position value of the letter, and then using a caesar cipher.
ABCDEFGHIJ
0123456789
c = (c + 3) % 26
c = (6 + 3) % 26
c = 9 % 26
c = 9
Now compare that value back to the string
G = J
This way makes it easier to comprehend, however im pretty sure its less efficient. (Im still a n00b though so maybe its acceptable)