Hi,
Also, depending on how bad they want the code, i dont think any chip is completely safe because an advanced method is to pop the top off the chip and examine the programmed die with a microscope, either automatic or by hand. The patterns in the die reveal the programming.
Then there is also single stepping. Some chips can be single stepped and that helps figure things out too.
There is probably no way to protect perfectly, because when the chip is programmed there is a physical change in the die that can be detected even though it is a small change.
Software is changing pretty fast for these things too. A year later nobody wants the code anyway because there is a better version or better product out
As far as compiling into the same exact machine code, if you use a different compiler you get a different output set of codes. So if they had your source code they could just compile with a different compiler. Some things would be similar i suppose though, but most definitely not everything.
You might be able to tell by the response times. If you had port A bit 1 change high to low when encoder 1 is turned to the right and theirs was the same, you might suspect some copying. You could then look at other pin responses.
The other problem is finding a product that has code that was stolen. You might never run across it unless you know where they sell the products and you do an active search. You'd also have to buy one to test