How did the US know they were going to be attacked by Japan?

The United States had broken the secret code used to send messages between Tokyo and the Japanese embassy in Washington DC