It is entirely fictional. In fact, Enigma and the associated code books were first captured from U-110 by the British in May 1941, before the Americans had entered the war. The British also captured material from U-559 in 1942.
The Americans first captured German Naval Enigma material in 1944 when they captured U-505 (their first capture of an enemy vessel at sea in 129 years).
U-571 was not involved in anything like the events depicted in this movie.
Shortly after the release of this film, BBC radio interviewed a former British naval officer, who had actually been involved in the recovery of code books from a German submarine on the point of sinking: he commented that the film had nothing to do with any historical facts, but was quite entertaining.