while line = gets
  min_char = line.chomp.scan(/[a-z]/).min_by(&:ord)
  min_char_diff = min_char.ord - ?a.ord

  word_chars = []
  line.chomp.each_char do |char|
    if ?a.ord <= char.ord && char.ord <= ?z.ord
      word_chars << (char.ord - min_char_diff).chr
    else
      word_chars << char
    end
  end

  sentence = word_chars.join('')
  predicate = -> {
    sentence.include?('the') ||
      sentence.include?('this') ||
      sentence.include?('that')
  }

  until predicate.call
    sentence = sentence.chars.map { |char|
      if ?a.ord <= char.ord && char.ord <= ?z.ord
        char.succ
      else
        char
      end
    }
  end

  puts sentence
end