The US had an excellent track record against Japanese codes and ciphers before World War II and this experience, combined with a variety of other sources of intelligence, helped the US – primarily the radio interception station and decryption centre Station HYPO run by Captain Joseph Rochefort at Pearl Harbor – deduce that an attack on Midway was in the offing.
Japanese naval codes were unlike German codes in World War II. They were primarily “book” ciphers while German codes used mechanical encipherment – the famous Enigma and Lorenz machines.