def pattern(word)
    word.each_char.each_cons(2).map {|a, b| (b.ord - a.ord) % 26}
end

$patterns = %w[the this that].map {|w| pattern(w)}

# Return: integer the number of shift
def get_key(enc)
    enc.scan(/[a-z]+/).each do |word|
        next if word.size < 3 or 4 < word.size

        if $patterns.include?(pattern(word))
            return ('t'.ord - word.ord) % 26
        end
    end
end

$<.each_line do |line|
    key = get_key(line)
    puts line.each_char.map {|c|
        next c unless c.match(/[a-z]/)
        ('a'.ord + (c.ord - 'a'.ord + key) % 26).chr
    }.join
end