Thus a mantra can be considered to be a linguistic device for deepening ones thought, or in the Buddhist context for developing the enlightened mind.
However it is also true that mantras have been used as magic spells for very mundane purposes such as attaining wealth and long life, and eliminating enemies.
The distinction between dharani and mantra is a difficult one to make. We can say that all mantras are dharanis but that not all dharanis are mantras. Mantras do tend to be shorter.
Both tend to contain a number of unintelligible phonic fragments such as Om, or Hu.m which is perhaps why some people consider them to be essentially meaningless.
Kukai made mantra a special class of dharani which showed that every syllable of a dharani was a manifestation of the true nature of reality in Buddhist terms that all sound is a manifestation of shunyata or emptiness of self-nature.
Thus rather than being devoid of meaning, Kukai suggests that dharanis are in fact saturated with meaning every syllable is symbolic on multiple levels.
One of Kukai's distinctive contributions was to take this symbolic association even further by saying that there is no essential difference between the syllables of mantras and sacred texts, and those of ordinary language.
If one understood the workings of mantra, then any sounds could be a representative of ultimate reality. This emphasis on sounds was one of the drivers for Kukai's championing of the phonetic writing system, the kana, which was adopted in Japan around the time of Kukai.
He is generally credited with the invention of the kana, but there is apparently some doubt about this story amongst scholars.
This mantra-based theory of language had a powerful effect on Japanese thought and society which up until Kukai's time had been dominated by imported Chinese culture of thought, particularly in the form of the Classical Chinese language which was used in the court and amongst the literati, and Confucianism which was the dominant political ideology.
In particular Kukai was able to use this new theory of language to create links between indigenous Japanese culture and Buddhism. For instance, he made a link between the Buddha Mahavairocana and the Shinto sun Goddess Amaterasu.
Since the emperors were thought to be descended form Amaterasu, Kukai had found a powerful connection here that linked the emperors with the Buddha, and also in finding a way to integrate Shinto with Buddhism, something that had not happened with Confucianism.
Buddhism then became essentially an indigenous religion in a way that Confucianism had not. And it was through language, and mantra that this connection was made.
Kukai helped to elucidate what mantra is in a way that had not been done before: he addresses the fundamental questions of what a text is, how signs function, and above all, what language is. In this he covers some of the same ground as modern day structuralists and others scholars of language, although he comes to very different conclusions.
In this system of thought all sounds are said to originate from 'a' which is the short sound in father. For esoteric Buddhism 'a' has a special function because it is associated with Shunyata or the idea that nothing exists in its own right, but is contingent upon causes and conditions.
In Sanskrit 'a' is a prefix which changes the meaning of a word into its opposite, so 'vidya' is understanding, and 'avidya' is ignorance (the same arrangement is also found in many Greek words, like example, 'atheism' vs. 'theism' and 'apathy' vs. 'pathos').
The letter 'a' is both visualised in the Siddham script, and pronounced in rituals and meditation practices. In the Mahavairocana Sutra which is central to Shingon Buddhism it says:
Thanks to the original vows of the Buddhas and Bodhisattvas, a miraculous force resides in the mantras, so that by pronouncing them one acquires merit without limits.
Kukai coined the word "shingon" (lit true word) as a Japanese translation of mantra. The word dharani derives from a Sanskrit root dh.r which means to hold, or maintain.
Ryuichi Abe (Professor of Japanese Religions at Harvard University) suggests that it is generally understood as a mnemonic device which encapsulates the meaning of a section or chapter of a sutra.
This is perhaps related to the use of verse summaries at the end of texts as in the Udana which is generally acknowledged as being in the oldest strata of the Pali Canon.