public class Vigenere {

	// http://www.asciitable.com/

	public static void main(String[] args) {
		String key = "gandalf";
		String plainText = "whatanunpredictableworldweliveright";

		String encryptedText = vigenereCipher(plainText, key);
		String decriptedText = vigenereDecipher(encryptedText, key);
		System.out.println(decrypt(encryptedText, key));

		System.out.println(encryptedText);
		System.out.println(decriptedText);
		System.out.println((-2) % 26);

	}

	public static String vigenereCipher(String plainText, String key) {
		String cipherText = "";
		plainText.toLowerCase();
		plainText.trim();
		key.toLowerCase();
		for (int i = 0; i < plainText.length(); i++) {
			char letter = (char) (((int) plainText.charAt(i) - (int) 'a'
					+ (int) key.charAt(i % key.length()) - (int) 'a') % 26 + (int) 'A');
			cipherText = cipherText + letter;
		}
		return cipherText;
	}

	public static String vigenereDecipher(String cipherText, String key) {

		String plainText = "";
		String plaint = "";
		cipherText.toUpperCase();
		key.toLowerCase();

		for (int i = 0; i < cipherText.length(); i++) {
			int cipherAt = (int) cipherText.charAt(i) - (int) 'A';
			int keyAt = (int) key.charAt(i % key.length()) - (int) 'a';
			int resultKey = (cipherAt - keyAt);

			System.out.println(resultKey);

			if (resultKey < 0) {
				resultKey = resultKey + 26;
				System.out.println(resultKey);
			}

			resultKey = (int)resultKey % 26 + (int) 'a';
			plainText = plainText + (char) resultKey;

		}
		return plainText;
	}

	static String decrypt(String text, final String key) {
    String res = "";
    text = text.toUpperCase();
    for (int i = 0, j = 0; i < text.length(); i++) {
        char c = text.charAt(i);
        if (c < 'A' || c > 'Z') continue;
        res += (char)((c - key.charAt(j) + 26) % 26 + 'A');
        j = ++j % key.length();
    }
    return res;
  }
}

@@ -302,59 +302,8 @@
 ey);
-%0A%09%09System.out.println(decrypt(encryptedText, key));
 %0A%0A%09%09
@@ -1467,360 +1467,6 @@
 %09%7D%0A%0A
-%09static String decrypt(String text, final String key) %7B%0A    String res = %22%22;%0A    text = text.toUpperCase();%0A    for (int i = 0, j = 0; i %3C text.length(); i++) %7B%0A        char c = text.charAt(i);%0A        if (c %3C 'A' %7C%7C c %3E 'Z') continue;%0A        res += (char)((c - key.charAt(j) + 26) %25 26 + 'A');%0A        j = ++j %25 key.length();%0A    %7D%0A    return res;%0A  %7D%0A
 %7D%0A

Remove bad algorit