// Program 82: Keyword Cipher import java.util.*; class KeywordCipher { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String key = sc.nextLine().toUpperCase(Locale.ROOT); String msg = sc.nextLine().toUpperCase(Locale.ROOT); if (!key.matches("[A-Z]+") || !msg.matches("[A-Z ]+")) { System.out.println("INVALID INPUT"); return; } StringBuilder cipher = new StringBuilder(); for (char c : key.toCharArray()) { if (cipher.indexOf(String.valueOf(c)) < 0) { cipher.append(c); } } for (char c = 'A'; c <= 'Z'; c++) { if (cipher.indexOf(String.valueOf(c)) < 0) { cipher.append(c); } } StringBuilder out = new StringBuilder(); for (char c : msg.toCharArray()) { out.append(c == ' ' ? ' ' : cipher.charAt(c - 'A')); } System.out.println("CIPHER ALPHABET: " + cipher); System.out.println("ENCRYPTED TEXT: " + out); } }