I suppose it depends on the country but to the best of my knowledge, rewriting content is not against the law.
If you infringe on someone’s copyright, they can sue you for doing that if that is what you are referring to. Keep in mind that going after someone for copyright infringement can be incredibly expensive to do and if you are rewriting some random article you found on the web that isn’t famous, chances are no one will care or want to pursue a copyright infringement lawsuit.
As for your question about if Google will know, it depends. Mainly it depends on what the finished content looks like. Google can easily tell if something has been spun by software and left that way because most of the time it is poorly written, full of errors and of low quality.
To make spun content unrecognizable by a search engine these days, you have to spend just about as much time perfecting the finished product as you would if you had re-written yourself.
Spun content makes this writer’s list of reasons you will get penalized along with some others related to content,
Hope that helps,