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: Wrong Answer)


import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	private static final int MIN_NUM_SHIFT = 1;
	private static final int MAX_NUM_SHIFT = 25;
	
	private static final int NOT_INCLUDE = -1;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<String> results = new ArrayList<String>();
		
		try{
			while(true){
				results.add(decryptString(sc.nextLine()));
			}
		}catch(NoSuchElementException e){
			//何もしない
		}
		
		sc.close();
		
		for(int i = 0; i < results.size(); i++){
			System.out.println(results.get(i));
		}
		
	}
	
	//暗号文字列を複合化した文字列を取得する
	public static String decryptString(String target){
		String result = target;
		for(int i = MIN_NUM_SHIFT; i <= MAX_NUM_SHIFT ; i++){
			String stringCandidate = shiftString(result, i * (-1));
			if(includeKeywords(stringCandidate)){
				result = stringCandidate;
				break;
			}
		}
		return result;
	}
	
	//対象文字列のアルファベットを指定された数ずらした文字列配列を取得する
	public static String shiftString(String target, int numShift){
		char[] result = target.toCharArray();
		for(int i = 0; i < target.length(); i++){
			if(isAlphabet(result[i])){
				int code = (int)result[i] + numShift;
				code = checkAndFixCode(code);
				result[i] = (char)code;
			}
		}
		return String.copyValueOf(result);
	}
	
	private static boolean includeKeywords(String target){
		if(target.indexOf("the") > NOT_INCLUDE){
			return true;
		}
		if(target.indexOf("this") > NOT_INCLUDE){
			return true;
		}
		if(target.indexOf("that") > NOT_INCLUDE){
			return true;
		}
		return false;
	}
	
	private static boolean isAlphabet(char c){
		if('a' <= c && c <= 'z'){
			return true;
		}
		else{
			return false;
		}
	}
	
	private static int checkAndFixCode(int code){
		if(code > 'z'){
			return 'a' + code - 'z' - 1;
		}
		if(code < 'a'){
			return 'z' - 'a' + code - 1;
		}
		return code;
	}
}