Problem:
Caesar Cipher

In cryptography, Caesar cipher is one of the simplest and most widely known encryption method. Caesar cipher is a type of substitution cipher in which each letter in the text is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 1, 'a' would be replaced by 'b', 'b' would become 'c', 'y' would become 'z', 'z' would become 'a', and so on. In that case, a text:

this is a pen

is would become:

uijt jt b qfo

Write a program which reads a text encrypted by Caesar Chipher and prints the corresponding decoded text. The number of shift is secret and it depends on datasets, but you can assume that the decoded text includes any of the following words: "the", "this", or "that".

Input

Input consists of several datasets. Each dataset consists of texts in a line. Input ends with EOF. The text consists of lower-case letters, periods, space, and end-of-lines. Only the letters have been encrypted. A line consists of at most 80 characters.

You may assume that you can create one decoded text which includes any of "the", "this", or "that" from the given input text.

The number of datasets is less than or equal to 20.

Output

Print decoded texts in a line.

Sample Input

xlmw mw xli tmgxyvi xlex m xsso mr xli xvmt.

Output for the Sample Input

this is the picture that i took in the trip.

Solution in JAVA (judge verdict: Accepted)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			while (sc.hasNext()) {
				String line = sc.nextLine();
				int offset = calculateIndex(line);
				System.out.println(encryptString(line, offset));
			}
		}
	}

	public static int calculateIndex(String str) {
		String[] ss = str.split(" ");
		for (String s : ss) {
			if (s.length() == 4) { // this, that
				if ((s.charAt(0) + 26 - 't') % 26 == (s.charAt(1) + 26 - 'h') % 26
						&& (s.charAt(0) + 26 - 't') % 26 == (s.charAt(2) + 26 - 'i') % 26
						&& (s.charAt(0) + 26 - 't') % 26 == (s.charAt(3) + 26 - 's') % 26) {
					return s.charAt(0) - 't';
				} else if ((s.charAt(0) + 26 - 't') % 26 == (s.charAt(1) + 26 - 'h') % 26
						&& (s.charAt(0) + 26 - 't') % 26 == (s.charAt(2) + 26 - 'a') % 26
						&& (s.charAt(0) + 26 - 't') % 26 == (s.charAt(3) + 26 - 't') % 26) {
					return s.charAt(0) - 't';
				}
			} else if (s.length() == 3) { // the
				if ((s.charAt(0) + 26 - 't') % 26 == (s.charAt(1) + 26 - 'h') % 26
						&& (s.charAt(0) + 26 - 't') % 26 == (s.charAt(2) + 26 - 'e') % 26) {
					return s.charAt(0) - 't';
				}
			}
		}
		return 0;
	}

	public static String encryptString(String str, int offset) {
		char[] result = new char[str.length()];
		for (int i = 0; i < str.length(); i++) {
			char cc = str.charAt(i);
			result[i] = cc;
			if (cc == ' ' || cc == '.') {
				continue;
			}
			result[i] = (char)((((result[i]) % 'a') + 26 - offset) % 26 + 'a');
		}
		return new String(result);
	}
}