I'm trying to do a basic caesar cipher shift by 1. This is my code so far but its off by one letter. Could someone tell me whats wrong with it? Thx
public void caesarCipher()
{
char[] letters = {'A','B','C','D','E','F','G','H','I','J','K',
'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
for(int x=0; x<letters.length; x++)
{
int n=1;
letters[x]=letters[(x+n)%26];
System.out.print(letters[x]);
}
}
This is the output of this code:
BCDEFGHIJKLMNOPQRSTUVWXYZB