For both the mummified body and the spiritual elements which had inhabited it upon earth had to be protected from a multitude of devils and fiends, and from the powers of darkness generally. These powers of evil had hideous and terrifying shapes and forms, and their haunts were well known, for they infested the region through which the road of the dead lay when passing from this world to the Kingdom of Osiris. The "great gods" were afraid of them, and were obliged to protect themselves by the use of spells and magical names, and words of power, which were composed and written down by Thoth.
In fact it was believed in very early times in Egypt that Ra the Sun-god owed his continued existence to the possession of a secret name with which Thoth had provided him. It was impossible, even for the Sun-god, to destroy this "Great Devil," but by reciting each morning the powerful spell with which Thoth had provided him he was able to paralyse all Aapep's limbs and to rise upon this world.
Since then the "great gods," even though benevolently disposed towards them, were not able to deliver the dead from the devils that lived upon the "bodies, souls, spirits, shadows and hearts of the dead," the Egyptians decided to invoke the aid of Thoth on behalf of their dead and to place them under the protection of his almighty spells. Inspired by Thoth the theologians of ancient Egypt composed a large number of funerary texts which were certainly in general use under the IVth dynasty (about 3700 B. C. ), and were probably well known under the 1st dynasty, and throughout the whole period of dynastic history Thoth was regarded as the author of the "Book of the Dead."