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}

and

{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.