I'm having trouble getting the Beale Cipher to work. For anyone unfamiliar, it's basically the ceasar cipher, only a bit cooler.
Take the decrypted message from the first cryptogram, and have it be the key to solving the next cipher. How this cipher works
0123456789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 (These values can be anything that you really want, I set a to zero instead of
abcde fgh i j k l m n o p q r s t u v w x y z 1 just for the hell of it)
Key: “STRINGOFWORDSSTRINGOFWORDSSTRINGOFWORDS...”
Message “THEPROBLEMISNOTTHEPROBLEMTHEPROBLEMISYOURATTITUDEABOUTTHEPROBLEM,DOYOUUNDERSTAND”
Encryption: S = 18. S applies to the T of the first letter of the message. Shift T 18 letters
T becomes L
“LAVXFU…”
I have two problems. Right now, it's not properly encrypting. And the second problem, is, as you can see, the key isn't always going to be the same length of the message, but I'm failing to think of a loop that will take the key message, and continue to add it onto itsself until it reaches the length of the message you want to encrypt.
public void encrypt2(String str, String key)
{
/*for(int z = 0; z < str.length(); z++)
{
char kCh = key.charAt(z);
key += kCh;
}*/
for(int i= 0; i < str.length(); i++)
{
// the Character in the string
char baelleCh = str.charAt(i);
for(int k=0; k < key.length(); k++)
{
// The character in the key
char ch = key.charAt(i);
// if the character in the key is a space
if(ch == ' ')
{
// crypted = the character
char crypted = ch;
cryptedString2 += crypted; // the character is added onto the string
}
else if(ch == 'a')
{
shift = 0; // shift is nothing
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); // crypted is set to the character in the string minus value of a, plus the shift
cryptedString2 += crypted; // mod 26 for the alphabet, plus the value of a
}
else if(ch == 'b')
{
shift = 1;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'c')
{
shift = 2;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'd')
{
shift = 3;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'e')
{
shift = 4;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'f')
{
shift = 5;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'g')
{
shift = 6;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'h')
{
shift = 7;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'i')
{
shift = 8;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'j')
{
shift = 9;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'k')
{
shift = 10;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'l')
{
shift = 11;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'm')
{
shift = 12;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'n')
{
shift = 13;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'o')
{
shift = 14;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'p')
{
shift = 15;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'q')
{
shift = 16;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'r')
{
shift = 17;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 's')
{
shift = 18;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 't')
{
shift = 19;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'u')
{
shift = 20;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'v')
{
shift = 21;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'w')
{
shift = 22;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'x')
{
shift = 23;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'y')
{
shift = 24;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else if(ch == 'z')
{
shift = 25;
char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
cryptedString2 += crypted;
}
else
{
System.out.println("Bug; did not reach a letter");
}
}
}
}
I will be available to answer any questions in regards to this through this post or private message. I'm hoping to have this completed ASAP as it's what I'm working on for my final project this semester.