Magic was the codename given for the American operation to break the Japanese diplomatic and military codes. The Communication Special Unit (U.S. Navy) and the Signals Intelligence Section (US Army) worked together in monitoring the traffic of coded messages sent by the Japanese Government and the Imperial Headquarters to their commanders at sea and in the field.
In 1939 Japan began using a new cipher machine invented by Jinsaburo Ito. Nicknamed the Purple Machine, the code was not broken until September 1940 by the Army cryptanalyst William Friedman. However, because of the large volume of intelligence being received by the staff of Magic, they were unable to give adequate warnings about the proposed attack at Pearl Harbor.
With increases in the number of people working at Magic they were able to discover the attack plan at the Battle of Midway. This enabled Admiral Chester Nimitz to use this information to fight off a much larger force and halt the Japanese offensive in the Pacific.