import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; public class Hello { private static Scanner sc = new Scanner(System.in); private static Scanner in; private static String message; private static String mappedKey; public static void main(String...s){ String text = sc.nextLine(); String key = sc.nextLine(); StringBuilder outputT = new StringBuilder(); StringBuilder outputK = new StringBuilder(); try { FileReader fstext = new FileReader(text); FileReader fsKey = new FileReader(key); BufferedReader readerT = new BufferedReader(fstext); BufferedReader readerK = new BufferedReader(fsKey); String lineT = readerT.readLine(); String lineK = readerK.readLine(); while(lineT != null && lineK != null) { outputT = outputT.append(lineT); lineT = readerT.readLine(); outputK = outputK.append(lineK); lineK = readerK.readLine(); } readerT.close(); readerK.close(); }catch (FileNotFoundException f){ System.out.println("File not found"); } catch(IOException ex) { System.out.println( "Error reading file "); } String enc = encrypt(outputT.toString(), outputK.toString()); System.out.println(enc); System.out.println(decrypt(enc, outputK.toString())); System.out.println(); } static String encrypt(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) - 2 * 'A') % 26 + 'A'); j = ++j % key.length(); } return res; } 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; } }