Your code does
NOT give out the cipher text. It struggles after some characters and gives nonsense.
for (int i = 0; i < keywordLength; i++)
{
if (x < ciphertext.length())
{
plaintext += ciphertext.charAt(x);
x++;
if (Character.isSpace(ciphertext.charAt(x - 1)))
{
plaintext += ciphertext.charAt(x);
x++;
}
y = x;
}
}
I guess that works as long as the keyword is longer than the cipher text.
Also please think about the concept of OOP. It seems that you've not really understood what OOP means. I struggled upon the
private static String encrypt()
- which means it does not get any arguments but delivers a value back. Pretty strange for such a function.
Entering text and result output should be done in your main, leaving just the encryption and decryption to your methods. keep them functional! don't give them several tasks to do. 1 task for 1 function.
Also please don't make the methods static - init an object (might be named
DeEncrpyter
or even "K" <- KAPITAL K that is!! ) and work with it.