# How do I generate decryption keys for the IDEA algorithm from the 128 bit key?

I am trying to implement IDEA algorithm in C#, just to learn how it works. I have taken a 128 bit binary key and generated the 52 encryption keys using the following code:

static ushort[] getKeys(string binaryKey)
{
ushort[] keys = new ushort[52];
int index = 0;
while (true)
{
int bitPos = 0;
keys[index++] = Convert.ToUInt16(binaryKey.Substring(bitPos, 16), 2);
bitPos += 16;
keys[index++] = Convert.ToUInt16(binaryKey.Substring(bitPos, 16), 2);
bitPos += 16;
keys[index++] = Convert.ToUInt16(binaryKey.Substring(bitPos, 16), 2);
bitPos += 16;
keys[index++] = Convert.ToUInt16(binaryKey.Substring(bitPos, 16), 2);
bitPos += 16;
if (index == 52)
break;
keys[index++] = Convert.ToUInt16(binaryKey.Substring(bitPos, 16), 2);
bitPos += 16;
keys[index++] = Convert.ToUInt16(binaryKey.Substring(bitPos, 16), 2);
bitPos += 16;
keys[index++] = Convert.ToUInt16(binaryKey.Substring(bitPos, 16), 2);
bitPos += 16;
keys[index++] = Convert.ToUInt16(binaryKey.Substring(bitPos, 16), 2);
bitPos += 16;
binaryKey = binaryKey.Substring(25) + binaryKey.Substring(0, 25);
}
return keys;
}


but now I cannot understand how to get those decryption keys. I couldn't find enough text on the matter too.

-
For folks who don't know C#, ushort is a 16 bit unsigned data type and the string binaryKey in my code is strictly 128 bits. –  Nikhil Girraj Apr 7 '13 at 19:40
If I understand IDEA right, you need the same sub-keys for decryption as for encryption. For the $\odot$ operations, you then need to divide, not multiply (which means multiplying with the multiplicative inverse of your key). –  Paŭlo Ebermann Apr 7 '13 at 21:06
Please note also that this is not a programming site, so it would be better if you express what your program does as a formula (or a series thereof) instead of a source code in any programming language. –  Paŭlo Ebermann Apr 7 '13 at 21:31
@Paŭlo Ebermann: That doesn't seem to work, although I believe that the sub-keys generated by the above method are correct! +I understand that this is not a programming Q&A but I thought they are closely related, to some extent. I'll be careful next time. –  Nikhil Girraj Apr 8 '13 at 4:45
I did not had any problem with 'Modular Inverse'. I am stuck with the rest of the straightforward! –  Nikhil Girraj Apr 9 '13 at 14:15