the British cracked Enigma in 1941, and from then they were able to completely destroy the 300-400 German u-boats, because they were intercepting and decrypting u-boat radio traffic, so they always knew where the u-boats were going. The only reason the Allies allowed the u-boats to continue winning small victories was to preserve the illusion that Enigma was still secure to prevent the Germans from switching to another cipher system. So when you see depictions of exciting historical battles against u-boats, keep in mind that it was not a level playing field due to the strategic advantage of superior SIGINT by the Allies.