"How he encountered you on the way" (Deuteronomy 25:18). Rabbi Yehudah, Rabbi Nechemyah, and the Rabbis. Rabbi Yehudah says: "How he encountered you" means he defiled you, as you say, "from a nocturnal emission" (Deuteronomy 23:11). Rabbi Nechemyah said: He read you, literally. And what did Amalek do? He went down to the archive of Egypt and took the records of the tribes, on which their names were inscribed according to the count of the bricks. He would stand outside the cloud and call out to them: "Reuben, Simeon, Levi, come out, for I am your brother, and I wish to conduct trade with you." When they came out, he killed them. And the Rabbis say: "He encountered you" means he cooled you off before others. Rabbi Chanina said: To what is the matter comparable? To a boiling bath into which no creature could go down. A certain worthless man came, leaped, and went down into it; even though he was scalded, he cooled it off before others. So too, when Israel went out from Egypt and the sea was split before them and the Egyptians were sunk within it, dread of them fell upon all the nations, as it is said, "Then the chiefs of Edom were terrified... terror and dread fell upon them" (Exodus 15:15-16). When Amalek came and joined battle with them, even though he received what was his at their hands, he cooled them off before the nations of the world.
Why Amalek Encountered Israel - Three Rabbis on a Cooled Bath
Midrash Tanchuma Buber, Ki Teitzei 13:1
אשר קרך בדרך וגו' (דברים כה יח), ר' יהודה ור' נחמיה ורבנן, ר' יהודה אומר, אשר קרך, טימאך, כד"א מקרה לילה וגו' (שם כג יא), ר' נחמיה אמר קראך ממש, ומה עשה עמלק, ירד לארכיון של מצרים, ונטל טימוסיהן של שבטים, שהיה שמם חקוק עליהם במתכונת הלבנים, והיה עומד חוץ לענן, והיה קורא להם, ראובן שמעון לוי, פוקו דאנא אחיכון, ובעינא למיעבד עמכון פרקמטיא, כיון שהיו יוצאין, היה הורג אותם, ורבנן אמרין קרך, הקירך לפני אחרים, אמר ר' (הונא) [חנינא] משל למה מהדבר דומה, לאמבטי רותחת שלא היה בריה יכולה לירד בתוכה, בא בן בליעל אחד קפץ וירד לתוכה, אע"פ שנכוה, הקירה לפני אחרים, אף כך כשיצאו ישראל ממצרים, ונקרע הים לפניהם, ונשתקעו המצרים לתוכו, נפל פחדם על כל האומות, שנאמר אז נבהלו אלופי אדום וגו' [תפול עליהם אימתה ופחד (שמות טו טו טז) ], כיון שבא עמלק ונזדווג להם, אע"פ שנטל את שלו מתחת ידיהן, הקירן לפני אומות העולם.