If I steal someone's algorithm, how would anyone be able to prove that I am using their algorithm? Only I have access to the code for the algorithm?
Unless someone sees my code, they can't say what algorithm is actually being executed?
George White's answer succinctly gives an answer to this question in its context, the only thing I could add from a more technical perspective, since I sense there is some curiosity from that angle is that:
You can only patent algorithms in a coupled with other tangible components as part of a system, method or computer program product, and not merely the algorithm itself, and that only. It may seem a technicality, but I sense this questions taps into that, and it is, in fact, an important consideration: Not seeing your code does not mean one is unable to define the process flow of software.
For example: If, upon approaching my car's door a camera coupled with all the necessary hardware and software to verify its me, opens or unlocks the door, from a patent perspective, if the method of opening a car door in this way (or the system comprising of all the hardware and software components for this) is able to do this as such as is described in a granted patent (or potentially a provisional patent) if the necessary components of the system, including a process flow of the software, regardless if the code itself is written or even structured differently (this is not copyright!), if it actually goes through the same steps generally defined in a patent application, for example, in a flow chart or verbally described step by step, it will be a patent infringement still.
In some cases this can be proven merely by what the software does. Even simply wedging in extra steps in the process flow that does not substantially improve, and neither does it worsen or impair the software component, it will likely be violative any ways.
But, generally, it all comes down to the steps set forth in the software component: If those match, and it can be, with reasonable probability, proven that they are infringing, the actual way the code is written and/or structured is a distinction without a difference in the eye of patent law, a suit can be merited, and the steps may ensue that George White described on court.
In civil lawsuits, including patent infringement,there is something called discovery where a judge requires the defendant to expose information relevant to the case to the plaintive.
Also, patent owners can attempt to reverse-engineer products to look for infringement. It is not only software. Integrated circuits can be analyzed by pealing away layers. https://electronics.stackexchange.com/questions/13472/is-it-possible-to-reverse-engineer-a-chip-design
See answer to similar question How is patent infringement usually being discovered?