A ninja (忍者) or shinobi (忍び) was a covert agent or mercenary of feudal Japan specializing in unorthodox arts of war. The functions of the ninja included espionage, sabotage, infiltration, and assassination, as well as open combat in certain situations. The ninja, using covert methods of waging war, were contrasted with the samurai, who had strict rules about honor and combat. In his Buke Myōmokushō, military historian Hanawa Hokinoichi writes of the ninja:
The mysterious nature of the ninja has long captured popular imagination in Japan, and later the rest of the world. Ninjas figure prominently in folklore and legend, and as a result it is often difficult to separate historical fact from myth. Some legendary abilities include invisibility,walking on water, and control over natural elements. The ninja is also prevalent in popular culture, appearing in many forms of entertainment media.The origin of the ninja is obscure and difficult to determine, but can be surmised to be around the 14th century. However, the antecedents to the Ninja may have existed as early as the Heian and early Kamakura eras. Few written records exist to detail the activities of the ninja. The word shinobi did not exist to describe a ninja-like agent until the 15th century, and it is unlikely that spies and mercenaries prior to this time were seen as a specialized group. In the unrest of the Sengoku period (15th - 17th centuries), mercenaries and spies for hire arose out of the Iga and Kōga regions of Japan, and it is from these clans that much of later knowledge regarding the ninja is inferred. Following the unification of Japan under the Tokugawa shogunate, the ninja descended again into obscurity. However, in the 17th and 18th centuries, manuals such as the Bansenshukai (1676) — often centered around Chinese military philosophy — appeared in significant numbers. These writings revealed an assortment of philosophies, religious beliefs, their application in warfare, as well as the espionage techniques that form the basis of the ninja's art. The word ninjutsu would later come to describe a wide variety of practices related to the ninja.