class DoubleBreastedInterruptedKeyCipher { static String encode(String text) { // Define the vowel and consonant lists List vowels = ['A', 'E', 'I', 'O', 'U']; List consonants = [ 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z' ]; // Create a map for easy lookups Map vowelMap = {}; Map consonantMap = {}; // Fill the maps by mirroring the lists for (int i = 0; i < vowels.length; i++) { vowelMap[vowels[i]] = vowels[vowels.length - 1 - i]; } for (int i = 0; i < consonants.length; i++) { consonantMap[consonants[i]] = consonants[consonants.length - 1 - i]; } // Encode the text StringBuffer encoded = StringBuffer(); for (int i = 0; i < text.length; i++) { String char = text[i].toUpperCase(); if (vowelMap.containsKey(char)) { encoded.write(vowelMap[char]); } else if (consonantMap.containsKey(char)) { encoded.write(consonantMap[char]); } else { encoded.write(char); // Keep non-alphabet characters unchanged } } return encoded.toString(); } static String decode(String text) { // The decoding process is the same as encoding for this cipher return encode(text); } }