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 (Python):
a = [['the'], ['this'], ['that']]
for i in range(25):
    for b in a:
        s = ''
        for c in b[-1]:
            s += chr((ord(c) - ord('a') + 1) % 26 + ord('a'))
        b.append(s)


def f(s):
    for b in a:
        for i in range(26):
            if s.find(b[i]) != -1:
                t = ''
                for c in s:
                    if c.isalpha():
                        t += chr((ord(c) - ord('a') - i + 26) % 26 + ord('a'))
                    else:
                        t += c
                return t
    return None

try:
    while True:
        print f(raw_input())
except:
    pass

Solution (Python):
import string, sys

alpha = 'abcdefghijklmnopqrstuvwxyza'
tbl = string.maketrans(alpha[:-1], alpha[1:])

for s in sys.stdin:
  while not('the' in s or 'that' in s or 'this' in s):
    s = s.translate(tbl)
  print s[:-1]

Solution (Python):
import sys, string
alpha = 'abcdefghijklmnopqrstuvwxyza'
tbl = string.maketrans(alpha[:-1], alpha[1:])
for s in sys.stdin:
  while not('the' in s or 'this' in s or 'that' in s):
    s = s.translate(tbl)
  print s[:-1]

Solution (Python):
a = 'abcdefghijklmnopqrstuvwxyz'

while True:
    try:
        s = input()
    except:
        break
    for n in range(1, 27):
        t = s.translate(str.maketrans(a, a[n:] + a[:n]))
        if 'the' in t or 'this' in t or 'that' in t: break
    print(t)

Solution (Python):
import sys
a = 'abcdefghijklmnopqrstuvwxyz'

for s in sys.stdin:
    for n in range(1, 27):
        t = s[:-1].translate(str.maketrans(a, a[n:] + a[:n]))
        if 'the' in t or 'this' in t or 'that' in t: break
    print(t)

Solution (Python):
while True :
    try :
        string = input()
    except EOFError :
        break
    
    for i in range(26) :
        new_string = []
        for j in range(len(string)) :
            if 97 <= ord(string[j]) <= 122 :
                x = ord(string[j]) + i
                if x > 122 :
                    x -= 26
                new_string.append(chr(x))
            else :
                new_string.append(string[j])
        new_string = ''.join(new_string)
        if 'the' in new_string or 'this' in new_string or 'that' in new_string :
            print(new_string)
            break

Solution (Python):
def rot(s, n):
    anslet = ''
    for let in s:
        if let in alp:
            anslet = anslet + chr(ord('a') + (ord(let) - ord('a') + n) % 26)
        else:
            anslet = anslet + let

    return anslet

alp = 'abcdefghijklmnopqrstuvwxyz'

while True:
    try:
        letlst = input()

    except:
        break

    for i in range(27):
        word = rot(letlst, i)
        if ('this' in  word) or('that' in word) or ('the' in word):
            num = i

    letlst = rot(letlst, num)
    print(letlst)

Solution (Python):
def slide(c):
    c = ord(c) + 1
    if c > ord('z'):
        c = ord('a')
    return chr(c)
    
while 1:
    try:
        s = input()
        ans = ""
        while 1:
            if "the" in s or "this" in s or "that" in s:
                print(s)
                break
            for i in range(0,len(s)):
                if ord(s[i]) >= ord('a') and ord(s[i]) <= ord('z'):
                    ans += slide(s[i])
                else:
                    ans += s[i]
            s = ans
            ans = ""
    except:
        break

Solution (Python):
ca = ord('a')
def convert(s, d):
    res = []
    for c in s:
        if c not in ' .':
            c = chr(((ord(c) - ca + d) % 26) + ca)
        res.append(c)
    return "".join(res)
for line in open(0).readlines():
    s = line.strip()
    for d in range(26):
        s0 = convert(s, d)
        if "the" in s0 or "this" in s0 or "that" in s0:
            print(s0)
            break

Solution (Python):

def cipher(s, k):
    l = list(s)
    r = []
    for i in l:
        if i.islower():
            i = chr((ord(i) - ord('a') + k)%26 + ord('a'))
        r.append(i)
    return "".join(r)

while True:
    wordset  = { "this", "that", "the" }
    try:
        s = input()

    except EOFError:
        break

    for i in range(0,26):
        t = cipher(s,i)
        w = set(t.split())
        if len(w & wordset ) > 0:
            print(t)
            break

Solution (Python):
if __name__ == '__main__':

	A = "abcdefghijklmnopqrstuvwxyz"

	while True:
		try:
			line = input()

			for d in range(1,27):
				t = line.translate(str.maketrans(A,A[d:] + A[:d]))
				if 'the' in t or 'this' in t or 'that' in t:
					print(t)
					break

		except EOFError:
			break

Solution (Python):
while True:
    try:
        strings=input()

        for i in range(26):
            _strings=""
            for s in strings:
                if ord('a')<=ord(s) and ord(s)<=ord('z'):
                    _strings+=chr((ord(s)-ord('a')+1)%26+ord('a'))
                else:
                    _strings+=s
            strings=_strings
            if "the" in strings or "this" in strings or "that" in strings:
                print(strings)
                break
    except EOFError:
        break

Solution (Python):
letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
while True:
  try:
    s = input()
  except:
    break
    
  l = len(s)
  for i in range(26):
    t = ""
    for j in range(len(s)):
      c = s[j]
      if 'a' <= c and c <= 'z':
        x = letters.index(c)
        cc = letters[(x + i) % 26]
        t += cc
      else:
         t += c
    if ("the" in t) or ("this" in t) or ("that" in t):
      print(t)

Solution (Python):
while True:
  try:
    caesar = input()
  except EOFError:
    break
  for i in range(26):
    raw_letters = []
    for j in range(len(caesar)):
      if caesar[j] == " " or caesar[j] == ".":
        raw_letters.append(caesar[j])
      else:
        letter = ord(caesar[j])+(i+1)
        
        if letter > 122:
          raw_letters.append(chr(letter-26))
        else:
          raw_letters.append(chr(letter))
    raw_strings = "".join(raw_letters)
    if ('the' in raw_strings) or ('this' in raw_strings) or ('that' in raw_strings):
      print(raw_strings)
      break

Solution (Python):
import sys

def caesar(c, n):
	cint = ord(c)
	return chr((cint+n-97)%26+97)

keyword = ['the', 'this', 'that']

for line in sys.stdin:
	slist = line.split()
	indx = 1
	while True:
		decodelist = []
		for i in range(0, len(slist)):
			word = ''
			for j in range(0, len(slist[i])):
				if slist[i][j] == '.': word = word+'.'
				else: word = word+caesar(slist[i][j], indx)
			decodelist.append(word)
		anotherlist = []
		for i in range(0, len(decodelist)):
			word = ''
			for j in range(0, len(decodelist[i])):
				if slist[i][j] == '.':
					anotherlist.append(word)
					word = ''
				else: word = word + decodelist[i][j]
			anotherlist.append(word)
		flag = False
		for i in range(0, 3):
			if keyword[i] in decodelist or keyword[i] in anotherlist:
				ans = decodelist[0]
				for j in range(1, len(decodelist)):
					ans = ans + ' ' + decodelist[j]
				print ans
				flag = True
				break
		if flag: break
		indx += 1

Solution (Python):
import sys
  
def get_shifted_char(shift_count, ch):
    if ord(ch) >= ord('a') and ord(ch) <= ord('z'):
        return chr(((ord(ch)-71-shift_count) %26 + 97))
    else:
        return ch


for enc_text in sys.stdin:
    text_list = list(filter(lambda s:len(s)==3 or len(s)==4,enc_text.strip().split()))

    shift_count = 1

    while(shift_count < 27):
        flg = False
        for text in text_list:
            decoded = ''.join(list(map(lambda c:get_shifted_char(shift_count,c),text)))
            if decoded == "the" or decoded == "this" or decoded == "that":
                flg = True
        if flg:
            break
        shift_count += 1

    print(''.join(list(map(lambda c:get_shifted_char(shift_count,c),enc_text.strip()))))

Solution (Python):
import string
while(1):
    try:
        text = input()
        words = text.split()
        stop = 0
        for i in range(26):
            if stop == 1:
                break
            a = []
            b = []
            for j in words:
                a.append("".join([chr((ord(k) + i - ord("a")) % 26 + ord("a")) if ord(k) >= ord("a") else k for k in j]))
                b.append("".join([chr((ord(k) + i - ord("a")) % 26 + ord("a")) for k in j if ord(k) >= ord("a")]))
            for j in b:
                if j in ["this","that","the"]:
                    print(" ".join(a))
                    stop = 1
                    break
    except EOFError:
        break

Solution (Python):
import re

caesar_trans = str.maketrans("abcdefghijklmnopqrstuvwxyz", "zabcdefghijklmnopqrstuvwxy")

while True:
    try:
        i = input()
        while True:
            if re.search("(^| )(the|this|that)(\.| |$)", i) is not None:
                print(i)
                break
            i = i.translate(caesar_trans)
    except EOFError:
        break

Solution (Python):
while(1):
    try:
        slist = list(map(str, input().split()))
    except:
        break

    rot = 0
    for i in range(26):
        for s in slist:
            ch = ""
            for c in s:
                if "a" <= c <= "z":
                    g = chr((ord(c) - ord("a") + i) % 26 + ord("a"))
                else:
                    g = c
                ch += g
            if ch == "this" or ch == "that" or ch == "the":
                rot = i
                break
        if rot != 0:
            break

    for i, s in enumerate(slist):
        ch = ""
        for c in s:
            if "a" <= c <= "z":
                g = chr((ord(c) - ord("a") + rot) % 26 + ord("a"))
            else:
                g = c
            ch += g
        if i == len(slist) - 1:
            print(ch)
        else:
            print(ch + " ", end="")

Solution (Python):
A = 'abcdefghijklmnopqrstuvwxyz'
 
while True:
    try: s = input()
    except: exit()
 
    for x in range(1, 27):
        ans = s[:-1].translate(str.maketrans(A, A[x:] + A[:x]))
        if 'the' in ans or 'this' in ans or 'that' in ans:
            print(ans + '.')
            break

Solution (Python):
import re


def code_shift(c, n_shift):
    return ord('a') + (ord(c) + n_shift - ord('a')) % 26


def get_candidate_plain(cipher, sym_ids, n_shift):
    plain = []
    for i, c in enumerate(cipher):
        if i not in sym_ids:
            plain.append(chr(code_shift(c, n_shift)))
        else:
            plain.append(c)
    plain = ''.join(plain)
    return plain


def decrypt(cipher):
    sym_ids = [m.start() for m in re.finditer(r'[\.\n\s]', cipher)]
    keyword = ['the', 'this', 'that']

    n_shift = 0
    while True:
        plain = get_candidate_plain(cipher, sym_ids, n_shift)
        for k in keyword:
            if plain.find(k) != -1:
                return plain
        n_shift += 1


if __name__ == '__main__':
    while True:
        try:
            cipher = input()
            print(decrypt(cipher))
        except:
            break

Solution (Python):
def rot_n(c, n):
    if 'a' <= c and c <= 'z':
        return chr((ord(c) - ord('a') + int(n)) % 26 + ord('a'))
    
    if 'A' <= c and c <= 'Z':
        return chr((ord(c) - ord('A') + int(n)) % 26 + ord('A'))
    
    return c

def rot(s, n):
    c = (rot_n(c, n) for c in s)
    return "".join(c)

while(True):
    try:
        s = input()
        for i in range(1,28):
            d = rot(s,i)
            if "this" in d.split() or "the" in d.split() or "that" in d.split():
                print(d)
    except:
        break

Solution (Python):
import sys

idx2alpha = {idx:s for idx,s in enumerate('abcdefghijklmnopqrstuvwxyz .\n')}
alpha2idx = {s:idx for idx,s in enumerate('abcdefghijklmnopqrstuvwxyz .\n')}

def rotate(s):
    idx = [next_w(alpha2idx.get(w)) for w in s]
    new_s = [idx2alpha.get(i) for i in idx]
    return ''.join(new_s)

def next_w(w_idx):
    if 25 < w_idx:
        return w_idx
    w_idx += 1
    return w_idx % 26

def decrypt(s):
    for _ in range(26):
        if 'the' in s or 'this' in s or 'that' in s:
            return s
        else:
            s = rotate(s)
    return 'Failed to decript!'

def run():
    for line in sys.stdin:
        print(decrypt(line.strip()))

if __name__ == '__main__':
    run()

Solution (Python):

s = input()
while 1:
    for diff in range(0,26):
        dec = []
        for c in s:
            chn = ord(c)
            if 97 <= chn < 97+26:
                chn -= 97 + diff
                chn = (chn % 26) + 97
                dec.append(chr(chn))
            else: dec.append(c)
        ss = ''.join(dec)
        if 'the' in ss or 'that' in ss or 'this' in ss:
            print(ss)
            break
    try: s = input()
    except EOFError: break