Click Here to go back to the homepage.

The Key to Cryptography Solution:


import java.util.*;
//https://open.kattis.com/problems/keytocrypto
public class Kattis {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String cipher = sc.nextLine();
    StringBuilder secretWord = new StringBuilder(sc.nextLine());
    StringBuilder origMessage = new StringBuilder();
    for (int i = 0; i < cipher.length(); i++) {
      char decipheredChar = (char)((cipher.charAt(i) + 'A' - secretWord.charAt(i)) < 'A' ? cipher.charAt(i) + 'A' - secretWord.charAt(i) + 26 : (cipher.charAt(i) + 'A' - secretWord.charAt(i)));
      secretWord.append(decipheredChar);
      origMessage.append(decipheredChar);
    }
    System.out.println(origMessage);
  }
}