1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Nikhil Girraj Apr 7 '13 at 19:40
  • 1
    $\begingroup$ 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). $\endgroup$ – Paŭlo Ebermann Apr 7 '13 at 21:06
  • $\begingroup$ 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. $\endgroup$ – Paŭlo Ebermann Apr 7 '13 at 21:31
  • $\begingroup$ @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. $\endgroup$ – Nikhil Girraj Apr 8 '13 at 4:45
  • 1
    $\begingroup$ I did not had any problem with 'Modular Inverse'. I am stuck with the rest of the straightforward! $\endgroup$ – Nikhil Girraj Apr 9 '13 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.