@hints = { 4 => ['this', 'that'], 3 => ['the'] }

def g(s)
  s.chop.split.each { |w|
    h = @hints[w.length]
    next if h.nil?
    wb = w.bytes.to_a

    h.each { |h|
      hb = h.bytes.to_a
      c = 0.upto(w.length - 1).map { |i| hb[i] - wb[i] }.uniq
      return c.shift if c.size == 1
    }
  }
  return 0
end

while s = gets
  d = g(s)
  sb = s.bytes.to_a
  0.upto(s.size - 1).each { |i| sb[i] += d if sb[i] >= 97 && sb[i] <= 120 }
  puts sb.map(&:chr).join
end