Hashing Algorithm in Ancient Indian Music System

For those who are from an IT background hopefully you know what a hash means!! Here I present the first known hashing algorithm in the world, which of course is again from ancient India !! Well, we Indians are the world pioneers in Mathematics, as Einstein said ‘We owe a lot to the Indians who taught us how to count’ or read about Place Value not just Zero, which ancient Indians invented.

By the way, I did not discover this algorithm in ancient Indian texts. It is already a well known fact and I am just presenting it here.

OK, So let us refresh what a hash is

A hash is a mapping of variable length data to a fixed length, many a times some long text represented as a number or a fixed length text. The original text might be a single word, or a sentence or an entire document! The hashing algorithm converts it into a number or a fixed length text.

For ex: Say the text is ‘Gurudev’, then the hash of ‘Gurudev’ could be 16478.
OR Say the text is ‘I am an alien from some other planet’, then the hash of it could be AJD3D.
A number could be similarly given for an entire paragraph, or a whole document!!

Given a hashing algorithm, the hashed text or number for a given word, sentence, paragraph or document generated using that algorithm will always be the same.

Hashing techniques are used in software security systems, search engines, indexes, hash constructs like HashTable, HashMap etc.

Some hashes are difficult to reverse and require lot of computation to do so. Some hashes are impossible to reverse even with great computation. Which is why such hashing algorithms are used to store passwords in databases. So even if somebody takes control of your database, he/she will see only the hashed text and cant derive the password out of it!

Even if you know the algorithm, its very difficult to get back the original text and you will have to use brute force method where you try calculating all possible combinations to get back the original text, and this requires a lot of computing power and is practically impossible!!

Hence hashing algorithms are also used in security systems and SSL to encrypt given data like passwords etc. Most popular hashing algorithms are MD5, SHA-1, etc. The entire security system in the IT world today relies on the fact that it is practically impossible with the current computing power available to get back the original text from a hash. Well, quantum computing might change this scenario in the future!

There are however rare collisions possible in hashing algorithms where two different set of text might end up with same hash number. But this is very rare depending on the algorithm, and the chances are like one in 2^60 possibilities etc.

Hashing algorithms are also used in search engines (of course including google) to make search faster. It is always faster to compare fixed length text or numbers than lengthy text!!

Coming back to ancient Indian classical music system, the carnatic system as we all know is the world’s most ancient and scientifically the most accurate music system. Hindustani music system is a derivative of Carnatic system. Many people prefer to learn Hindustani than carnatic because Hindustani is easier compared to Carnatic. However, Carnatic is still prevalent in the southern Indian states.

Carnatic music system has 72 base ragas. Each raga in Indian music system depicts a mood. Some ragas are suitable to be played during sun rise, some during sunset, some produce a devotional feeling, some produce a romantic feeling, and so on… It is a common misconception that ragas are just a combination of specific notes. There are many other rules for a raga other than the notes specification, like which is a promiment note in that raga, which is a banned note for that raga, the identifier note sequence, etc

Just knowing the keys in a raga doesnt mean that one can claim that he/she knows that raga. Raga is much more than a technical rule! Western composers beware, dont fool people saying you have used a particular raga without knowing what it really is!

Coming back to base ragas in carnatic. Base ragas are the foundations of carnatic raga system and all other thousands of ragas are derived from these base ragas.

A base raga uses 7 major notes of an octave. Let us look at it in terms of a keyboard which will make things easier to understand. We know that an octave consists of 12 keys, i.e 7 white and 5 black.

In carnatic we need Sa, Re, Ga, Ma, Pa, Dha, Ni to form a base raga. Base raga is also called a melakartha raga. So there are 72 Melakarthas in carnatic.

Sa and Pa are constants i.e they have no other possible keys in a raga. See image below. S is Sa and P is Pa

Then For ‘Ma’ we have the third black key and fourth white key. So in a raga either of them could be used as Ma.

For ‘Ri’ and ‘Ga’ we have 4 keys between Sa and Ma.
For ‘Dha’ and ‘Ni’ we have 4 keys after Pa.

Since Ga always comes after Ri, out of the four keys we have 6 possible combinations for Ri-Ga
Suppose the four keys are R1, R2(is same as G1), R3(is same as G2) and G3
Then the six possible combinations are
{R1,G1},{R1,G2},{R1,G3} ,{R2,G2},{R2,G3},{R3,G3}

Similarly for Ni and Dha we have 6 combinations.
{D1,N1},{D1,N2},{D1,N3} ,{D2,N2},{D2,N3},{D3,N3}

So we have 2 combinations for Ma, 6 for Ri-Ga, 6 for Dha-Ni
Totally we have 2×6×6 =72 possible combinations in carnatic system for the base (called Melakartha) ragas.

So each raga has its melakartha number which is 1-72, and then we have the raga name. This is where the hashing algorithm comes into picture.

The hashing algorithm used to name a carnatic raga is called ‘KaTaPaYaDi’ system and using this algorithm, just by knowing the raga name one can calculate the Melakartha number of that raga and all the 7 base keys used in that raga!

Here we present the KaTaPaYaDi system.
Each consonant of an Indian language is assigned a number in this Katapayadi system as follows:

क(Ka)=1 ख(Ka)=2 ग(Ga)=3 घ(Ga)=4 ज़(Gnya)=5 च(Cha)=6 छ(Cha)=7 ज(Ja)=8 झ(Ja)=9 अ(Nya)=0
ट(Ta)=1 ठ(Ta)=2 ड(Da)=3 ढ(Da)=4 ण(Na)=5 त(Tha)=6 थ(Tha)=7 द(Dha)=8 ध(Dha)=9 न(Na)=0
प(Pa) =1 फ(Pha)=2 ब(Ba)=3 भ(Bha)=4 म(Ma)=5
य(Ya)=1 र(Ra)=2 ल(La)=3 व(Va)=4 श(Sha)=5 ़़ष(Sha)=6 स(Sa)=7 ह(Ha)=8 ळ(La)=9

Now you can see why this system is called Katapayadi. Ka=Ta=Pa=Ya=1

Now let us get directly into the Katapayadi hashing algorithm for ragas.

All we need is the first two consonants of the raga name to find the raga number and its keys. NOTE: Any consonant not attached to a vowel has to be ignored.

The steps involved are as follows. Say A and B are the first two consonants in the raga name. Then we proceed as follows:

Step 1: Get the Corresponding number for A and B from the above table as [AB]

Step 2: Reverse this number and there we are. We have got the raga number now!!!

Step 3: Note that we have two possible combinations for Ma i.e M1 and M2. So Melakartha is designed in such a way that all first 36 ragas use M1 and all 37-72 ragas use M2. So, if the Raga number we got in Step 2 is greater than 36 then Ma=M2 else Ma=m1

Step 4: Now we need to find the RG and DN combinations of the Raga. So we have a list of possible combinations for this as
{R1,G1},{R1,G2},{R1,G3} ,{R2,G2},{R2,G3},{R3,G3}
{D1,N1},{D1,N2},{D1,N3} ,{D2,N2},{D2,N3},{D3,N3}
Now divide the Raga Number by 6 (Since we have 6 possible combinations)

Step 5: If the remainder is zero:
then DN={D3N3} and Quotient number gives the RG combination number (like if quotient=2 then RG={R1,G2})

Step 6: If the remainder is non zero:
then remainder gives DN combination number and quotient+1 gives the RG combination number

As simple as that!!!

Now let us consider an example:
Consider MayaMalavaGowla Raga – Let us find its Raga Number and all Keys

We have A=Ma and B=Ya
So by looking at the above KaTaPaYaDi table we have A=5 and B=1
So the raga number is 15 and Ma=M1 (Since 15<37)!
Then we divide 15 by 6 we get quotient=2 and remainder=3
Since remainder is non zero, we have DN set as {D1N3} and RG set as {R1G3}!

So MayaMalavaGowla = Sa R1 G3 M1 Pa D1 N3

You can check the Complete Melakartha Raga List here and try the above algorithm on your own for other ragas!!

Please note that the above hashing algorithm is not limited only to identifying ragas. It is a common algorithm across many sanskrit texts. Long before Europe started wondering how to count using the roman numerals, Indians were already using hashing algorithms in their works!!

Note the Indian hashes are reversed numbers (from right to left, which is why we reversed it in Step 2 to get the original word) unlike the western hashes which are from left to right!

So if we have to hash TriShooL, we reverse hash it as 356 (not 653). This is natural because this is how we invented the place value system too. from right to left as units, tens, hundreds etc.

  • audi_krishnan

    Thanks to all of you for your views – especially to  the debate between the author (hitxp) and Kaushik.  It was exhilarating to read such spirited exchanges on so arcane a subject.
    If any one knows, kindly also throw some light on the mathematics involved in the process of teaching/learning the veda; I refer to the GHANAPADI and the PRASNA and other mathematical routines used.  I have had a very faint glimpse of these topics in the book containing articles and upadesas  by PUJYA PARAMACHARYAL of KANCHI .
    Thanks and regards to all,

  • http://www.subramanib.wordpress.com subramani

    Good one. can you suggest some good resources or give links to Ancient Indian teachings in the field of science & mathematics.

  • uma

    its great to see ur article.. can u tell any way to identify the raaga by extracting some features of a song..it will be great to hear from you.

  • Sudheep Elayidom

    We carnatic musicians frequently use it…Good work!!!!!!!

  • Sudheep Elayidom

    The concept we Carnatic musicians use it frequently


  • http://www.hotmail.com gunjoo

    hitxp, hello,

    I was wondering if you could possibly post a link with extra information on all of this. I am very interested in vedic mathematics but do not know where to look for good sources!

  • Nagarajan

    Dear Gurudev,
    Thanks for your great thoughts on Melakartha scheme. I am also one of those intrigued by the Melakartha scheme and Katapayadi Sankhya. Ofcourse there are many more amazing things about our carnatic music system.
    I have also put down my thoughts on Melakartha scheme and their coded names. I had sent them as an article to a few musicologists in Chennai for their reflection and a possible feedback. I wish to share this article with you and hopefully I will be lucky to get your feedback.
    If it is OK with you kindly give me your email ID.
    L V Nagarajan

  • Tom Sturges

    I’m confused if Ma is one of two adjacent notes surely the possible combinations for Ma include the ones where Ma is the higher note leaving five notes inbetween Sa and Ma meaning a possible combination of 10?

    Or is it the case that if Ma is the higher note, Ga can not take the place of the lower possible note of Ma in any of those ragas? And the other way round.

    Thankyou very much for your time.

    • http://www.facebook.com/kapaliv Kapali Viswanathan

      The following are the notes in the octet. 
      Sa, Ri1, Ri2 (Ga1), Ri3(Ga2), Ga3, Ma1, Ma2, Pa, Da1, Da2 (Ni1), Da3(Ni2), Ni3, [Sa]

      For every sampoorna (Melakarta) raga, you have to choose as follows. 
      1. Exactly one Ri, Ga, Ma, Da, Ni from the above list
      2. If you choose Ri2, then you cannot choose Ga1. Similar logic applies to Ri3, Da2, and Da3.

      With these two rules you have six possibilities in choosing Ri and Ga, six possibilities in choosing Da and Ni. Thus you have 36. When you multiply the two possibilities due to Ma you have 72. 

      This is the reason why the choice of Ma splits the Melakartha Circle into two. 


  • http://www.hitxp.com/ Gurudev

    Einstein once said that the
    Most incomprehensible thing about the world is that it is comprehensible :)

  • akshay

    very beautiful.excellent find.ah to only contemplate our elders is very tough.how am i going to contemplate about the eternal truth then?

  • http://www.hitxp.com/ Gurudev

    Yes Ramya
    you are right that it was jagadguru shankaracharya of puri who reintroduced vedic mathematics to the masses.

    Thanks Maitreyi / destinationsrik for your comments.

    Akilan I dont have any info about gayatri mantra and PI, but it definitely is the most powerful of the vedic mantras after OM with evolutionary secrets in it, summarizing the three vedas. The famous Geneticist and evolutionary biologist Haldane once said that “”the Gayatri Mantra should be carved on the doors of every laboratory of the world”"

  • Maitreyi

    The best thing about your articles is its simplicity covering the most complex information without revealing any actual complexity of the topic being discussed

  • Ramya

    Hope you know the actual vedic mathematics genius jagadguru shankaracharya of puri who was actually based from Tiruchirapalli .HIS HIGHNESS came to US for three months later died in Mumbai . I think the latest known vedic mathematician itself is this great shankaracharya.
    It seems pythagoras thereom was also originited near Kerala.
    Not only this Yoga the vedic science of physical exercise itselfs prove a lot about ancient India .


    Can KaTaPaYaDi scheme be applied to Gayathri Mantra in order to derive a number that signifies some mathematical explanation about the powerful mantra?

    The reason is that in one of the slokas, I have seen in the web sites that above scheme is applied to derive the meaning of Pi =3.14

  • http://srikslib.blogspot.com destinationsrik

    Such a wonderful information! Thanks.
    Raagas in deed has more meaning than just a combination of notes.

  • http://www.hitxp.com/ Gurudev

    And can you wonder how many times would I have thanked this great nation for having me as a part of it!

    Also, thanks for your wishes Sainath, I am a born optimist :)

  • Sainath

    Simply great…thanx i wonder how many times i am going to say thanx to you henceforth :) ..You are just amazing….I pray you succeed in all your noble dreams….

  • Krishna

    Excellent article. Made my fundamentals on carnatic music really clear.


  • http://www.hitxp.com/ hitxp


    First thing. The mathematics of Aryabhata and Bhaskara is NOT vedic Mathematics. Vedic Mathematics is limited to Vedas. Yes, There have been hundreds of great mathematicians in ancient India like Aryabhatta, Bhaskara, Brahmagupta, etc after the vedic era and they all have their ROOTS in the vedic mathematics.

    Second: Why is vedic mathematics taught as mental arithmetic to young students today? Definitely because it makes calculations faster with less use of paper and pen. Why is this possible? Because there are specific formulae and rules for calculations, unlike the generic ones we are taught in western mathematics. As I said, yes there is more to learn in Vedic math than in Western math to do the same thing!! But schooling is an age of learning and once they have learnt this , they can easily beat the students who are taught western mathematics any day!! Shakuntala Devi is a classic example! I am not sure whether you have actually read vedic mathematics before saying all this!!! There is no magic in vedic mathematics, the mental maths is pure specific algebra!!

    It is very wrong to say formal mathematical theory was absent in ancient India. You are making derogatory comments against ancient Indians without knowing anything!! I take strong exception to what you have said. Please go through at least some of the the ancient Indian mathematical texts before you say something like this.

    All the rules, the conditions, the usage, examples are all EXPLICITLY mentioned in the texts. What do you mean by absence of a formal mathematical theory? They have even talked about astronomical numbers so large which even today is not used often!! So many beautiful scenarios have been described about solving different kind of problems!!
    Please dont go on hearsay and write things. Look for yourself.

    You are again doing great injustice by saying vedic mathematics is based on intuition!! Vedic mathematics is pure science, it is not guesswork as you are suggesting!!


    Western mathematicis was a a generalized version of Indian mathematics and then it got developed on the basis of the same generalization. For this you need to know a bit of history. The 10 symbols used in base 10 system today originated from the Brahmi symbols of ancient India. This number system was spread to the rest of the world by Arab merchants who came to India for trade. Which is why they are called Hindu-Arabic Numerals. They used this place value based system for trade because they found it very easy to do simple business calculations like multiplication and division in their trade, instead of using the clumsy roman number system present then. But they used only the basic calculations, generalized multiplication, division etc, and this is what entered the western world. SIMPLE GENERALIZED CALCULATIONS from the Indian society.

    The sad part is while so many western researches and scholars have appreciated the ancient Indian mathematical treasure, we Indians ourselves are yet to recognize and give the true merit it deserves. Do you think the accurate speed of light calculated in ancient Indian texts millenia before the west did was based on Intuition??

    Even if you read some of the comments given by great modern western mathematicians and physicists on ancient Indian mathematics, you will find that their opinions are completely contrary to what you have said! I still dont understand what is your definition for a formal mathematical theory? How on earth can you say that there was no formal mathematical theory in ancient India?

    Einstein said, ‘We should be thankful to Indians who taught us how to count without which no major worthwhile scientific discovery would have been possible’! – without a formal mathematical theory?

    Actually your comments have inspired me to write a series of blogs on the vedic mathematics with examples and details. I am sure 99.9% of the people who comment on the pros and cons of Vedic Mathematics havent even read it properly! Do you know that it comes as a part of Atharva Veda and Atharva Veda is all about engineering ? Engineering without a formal mathematical theory? Have you by any chance read Vymanika Shastra, Vaayu Purana, etc ?

    I sincerely request you not to spread wrong information without having proper sources to quote. Now if I had not replied to your comment, and if somebody else had read your comments and taken it to be true, they would have thought that Vedic Mathematics is based on Intuition and there was no formal mathematical theory!! Please post the same question to a western mathematician who has studied ancient Indian mathematics and you will probably get an even more accurate answer.

  • Kaushik

    My first line got truncated. I meant
    “”The Katapayadi sankhya was indeed a great achievement of ancient Indian mathematics.”"

  • Kaushik

    The Katapayadi sankhya was indeed a great achievement of

    However, I find many generalizations in your article:

    “”Western world failed to understand the basics of Indian mathematics when they learnt it from us, which is why vedic mathematics is faster than western math!”"

    The first part is questionable and the second part is plainly wrong. What you are referring to as “”Vedic mathematics”" is a set of rules for mental arithmetic. The theory behind these was developed, but rarely stated explicitly in Indian mathematical texts. This is because the notion of a formal mathematical theory as we know it was largely absent in ancient Indian mathematics. Vedic mathematics is instead founded primarily on insight and intuition – which is certainly an integral part of mathematics. However, crass statements like the one above are uncalled for and do an injustice to both Indian and Western mathematics.

    Vedic mathematics is more than mere fast calculation.

    “”Western world started developing generic formulae for calculations while Indian math has specific formulae depending on the type of calculations.”"

    Precisely my above point.

    1) Indian math is more than a set of calculation rules. Aryabhatta and Brahmagupta discovered solutions for Diophantine equations centuries before the west did. You are actually belittling our mathematical tradition with such points.

    2) To a mathematician, the above statement reads as a negative for Indian mathematics.

    I also have a suggestion regarding your description of the Katapayadi sankhya as a “”hashing algorithm”". Yes, the method is a hashing algorithm in principle. However, you also need to consider that the intent of the scheme is not to prevent you from figuring out the first two consonants of a raga given its Melakarta number (nor is it very effective in doing so). The idea of the scheme is to provide a “”lookup table”" for ragas. Hence, a better description of the Melakarta scheme would be that it is a “”dictionary”" (in the computer science sense of the term).


  • http://www.hitxp.com/ hitxp


    thankx, it was reversed, corrected it!

  • kaav

    lovely article.
    one thing though, the ni-da combination should be

  • http://trivia.blogdrive.com kaushik

    an excellent entry. although i knew the KaTaPaYaDi sutra, and the way of finding the number of which melakartha raga it is, i didnt know the further use of it. good.