I could understand stealing copyrighted code being illegal, but using it to create a similar script isn't illegal surely?
Yes it illegal if the software or the idea is patented. Amazon have patented the idea of the Shopping Cart System (using cookies to go through a store) and are trying to shut down all other sites and scripters who have ever done something similar!