The general idea about software, algorithms and implementation details is:
- the more you produce something that is abstract and without significant details, like an mathematical algorithm, the less you are likely to have the right to patent that
- the more you can produce a detailed implementation the higher the chances are that you can protect your intellectual property with a patent.
For example if you know about JPEG, it's a general file container for bitmap images, its standard says nothing clear about any implementation details, if you just follow the JPEG standard you can't write useful code because it's too generic and does not gives you the implementation details that you need to read or write from an actual JPEG file.
However this kind of things is possible http://www.google.com/patents/US6724939 because it's 1 specific way of implementing this algorithm.
You can find some extra examples here http://en.wikipedia.org/wiki/Patentable_subject_matter
Remember that patenting means that a person registers that intellectual property, it's not about selling and paying for something, in fact you can just choose to patent something and not asking for royalty even if peoples uses that, you can patent something and prohibit the use of that technology without giving licenses, you can patent something and choose to sell licenses to use that technology.
If you find code with an "unknow source" your best chance is to change at least a little piece of code, rearrange the text or something like that.