Although ninja were almost always Japanese, the roots of the ninja philosophy lie in China, where Sun Tzu wrote "The Art of War" in the 4th or 5th century, B.C. "The Art of War" is a guide for military commanders that is still considered essential reading for modern military officers, as well as businesspeople. One part of the text in particular caused changes in the philosophy of Japanese warriors that would eventually lead to the ideology of the ninja. Chapter 13 (translated text) describes the advantages that can be gained by spreading disinformation amongst your enemies, and sowing confusion in their ranks through deception and sabotage. It also recommends that generals find out as much as possible about their enemy by using spies and other practical methods.
Much of this was antithetical to the Japanese way of waging war. For centuries, armies of foot soldiers and samurai would line up and call each other out to do honorable, one-on-one battle. The underhanded tactics espoused by Sun Tzu went against the grain. But the wisdom of using deception and espionage to win wars could not be denied, and many Japanese warriors came to grudgingly accept it.
The mixed feelings that the Japanese had toward the deceptive ways of the ninja, combined with the ninja's inherent secretiveness, makes studying the history of these shadowy warriors difficult. In many cases, Japanese historians simply left all mention of ninja out of historical documents. If they were mentioned, ninja were either elevated to the status of terrifying, supernatural beings, or were spoken of with contempt and disgust.