The algorithm IDEA consists of eight rounds. We will divide the block X to codifying, of 64 bits, in four parts(reports) X1, X2, X3 and X4 of 16 bits. We will name Zi to each of 52 subkeys of 16 bits that we are going to need. The operations that we will carry out in every round are the following ones: 1-To multiply X1 for Z1. 2-To add up X2 with Z2. 3-To add up X3 with Z3. 4-To multiply X4 for Z4. 5-A XOR makes between the results of the step 1 and the step 3 6-Do a XOR between the results of the step 2 and the step 4. 7-The result of the step multiplies 5 for Z5. 8-The results of the steps add 6 and 7. 9-The result of the step multiplies 8 for Z6. 10-The results of the steps add 7 and 9. 11-A XOR does between the results of the steps 1 and 9. 12-A XOR does between the results of the steps 3 and 9. 13-A XOR does between the results of the steps 2 and 10. 14-A XOR does between the results of the steps 4 and 10. 15-The exit of every iteration they will be four sub-blocks obtained in the steps 11, 12, 13 and 14, which will be the entry of the following cycle, in which we will use the following six subkeys, up to a whole of 48. At the end of everything we will exchange both central blocks (actually(indeed) with it we undo the exchange that we carry out in the steps 12 and 13). After the eighth iteration, the following transformation is realized: To multiply X1 for Z49. To add up X2 with Z50. To add up X3 with Z51. To multiply X4 for Z52. The first eight subkeys are calculated dividing the key of entry in blocks of 16 bits. The following ones eight are calculated rotating the key of entry 25 bits to the left side and returning to divide her, and this way successively. The necessary subkeys to decipher are obtained changing order the Zi and calculating his inverse ones for the sum or the multiplication. Since 216 + 1 is a prime number, we will never be able to obtain zero as product of two numbers, for what we do not need to represent the above mentioned value. When we are calculating products, we will use the zero to express the number 216 - |un one followed(consecutive) by 16 zeros-. This representation is coherent since the records that are used internally in the algorithm possess only 16 bits. Enjoy, and have a Happy calculation One simple Example: Decrypted of an EMM Digital+ (Spain) Original instruction: 21006DA0CA00006704654001920018F56C533A32C5526B3150 4793F1189C9DAE6447CD140F9ACB7963B662BB16BB53AF780E C4A340217877385B02A9090519F58EF9FEBE33269E23DF4623 9CF8BDDCAD43B6A67F72D5F44938F1C9BD40D0457B5030FA55 7A02678F9F1BDC8D8FE282 Select Key..........: 42 18 52 10 03 18 (EMM-G) 4001 Set of Keys 2 (RAM IKEY AC3) CRL.................: 3E Len of the message to decrypter: 96 bytes ======================= Step 1: RSA of 768 Bits ======================= M = F56C533A32C5526B31504793F1189C9DAE6447CD140F9ACB79 63B662BB16BB53AF780EC4A340217877385B02A9090519F58E F9FEBE33269E23DF46239CF8BDDCAD43B6A67F72D5F44938F1 C9BD40D0457B5030FA557A02678F9F1BDC8D8FE282 N = 87BABC043F6656A504011FF45D1F3778CEA37CFF305821CF4E D08B7F8D65CA97CE86C9B6CB045B465A69E6DF7CBAFF95CE27 2E0EF7C86EE6AC8B290F269E36DDC792F7A9C25EC607172D91 692FA39447DFEA17C4912BDFB4529F2B817849CFE5 E = 03 M ^ E mod N = A92B741C80DC49DDD0C81897C13110E9126F033657EE7F80C2 8DEA91134D48CC21E49D0E0B40F265FDCEA803A59224EA5DA3 BB74FBDB8BAD3BCFBC66E5CE0E0FD80C37A3D36E4F5F42450D DF50BF2BEDADD499175C2E6464C9F4326608367115 ================================================== = Step 2: To adjust finishes byte of the previous RSA ================================================== = To adjust the I finish byte of the message according to the bit 7 of the third byte of the Select Key Third byte of the select key: 18 (00011000 in binary) Last byte of the message....: 15 (00010101 in binary) 15 OR 80 = 15 Result: M = A92B741C80DC49DDD0C81897C13110E9126F033657EE7F80C2 8DEA91134D48CC21E49D0E0B40F265FDCEA803A59224EA5DA3 BB74FBDB8BAD3BCFBC66E5CE0E0FD80C37A3D36E4F5F42450D DF50BF2BEDADD499175C2E6464C9F4326608367115 ============================ Step 3: IDEACBC of 12 Rounds ============================ IDEACBC Key: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA We begin with the last block, we subject this block to the algorithm IDEA by means of the Key IDEACBC. The result XOR with the previous byte and so forth until arriving to the first byte that is only subjected to the IDEA, without XOR since is not precedent block. Block 12........: C9 F4 32 66 08 36 71 15 Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: D2 B7 08 FA 2D 28 0D 79 Crypted Block XOR Block 11 = 7F 63 91 ED 71 06 69 1D --> New block 12 Block 11........: AD D4 99 17 5C 2E 64 64 Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: D3 37 3A 93 CA 65 1A B2 Crypted Block XOR Block 10 = 91 72 37 4C 9A DA 31 5F --> New block 11 Block 10........: 42 45 0D DF 50 BF 2B ED Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: 40 26 30 78 BF E8 38 E3 Crypted Block XOR Block 9 = 98 2A 07 DB 6C 86 77 BC --> New block 10 Block 9........: D8 0C 37 A3 D3 6E 4F 5F Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: 2A 52 1A AC D9 79 57 5A Crypted Block XOR Block 8 = 11 9D A6 CA 3C B7 59 55 --> New block 9 Block 8........: 3B CF BC 66 E5 CE 0E 0F Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: 1F 5C 37 E3 7C 98 30 72 Crypted Block XOR Block 7 = 42 FF 8C 97 87 43 BB DF --> New block 8 Block 7........: 5D A3 BB 74 FB DB 8B AD Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: 25 F5 E4 0E 76 32 23 A8 Crypted Block XOR Block 6 = D8 3B 4C 0D D3 A0 07 42 --> New block 7 Block 6........: FD CE A8 03 A5 92 24 EA Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: 91 16 6A E0 63 8D 32 BA Crypted Block XOR Block 5 = B0 F2 F7 EE 68 CD C0 DF --> New block 6 Block 5........: 21 E4 9D 0E 0B 40 F2 65 Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: 85 EC 84 E9 5D 55 A8 AD Crypted Block XOR Block 4 = 47 61 6E 78 4E 18 E0 61 --> New block 5 Block 4........: C2 8D EA 91 13 4D 48 CC Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: 3E C0 B6 77 1D 58 AC 02 Crypted Block XOR Block 3 = 2C AF B5 41 4A B6 D3 82 --> New block 4 Block 3........: 12 6F 03 36 57 EE 7F 80 Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: B5 91 8C 7D 34 BA 91 5F Crypted Block XOR Block 2 = 65 59 94 EA F5 8B 81 B6 --> New block 3 Block 2........: D0 C8 18 97 C1 31 10 E9 Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: A5 94 45 FC 71 98 4E 30 Crypted Block XOR Block 1 = 0C BF 31 E0 F1 44 07 ED --> New block 2 Block 1........: A9 2B 74 1C 80 DC 49 DD Calculated with IDEACBC..: 20 37 BC 03 3B 5A 48 66 3B 99 1B F4 EE 80 81 BA Crypted Block..: 08 1C A4 54 95 AC 9E 0D --> New Block 1 Result: M = 081CA45495AC9E0D0CBF31E0F14407ED655994EAF58B81B62C AFB5414AB6D38247616E784E18E061B0F2F7EE68CDC0DFD83B 4C0DD3A0074242FF8C978743BBDF119DA6CA3CB75955982A07 DB6C8677BC9172374C9ADA315F7F6391ED7106691D ======================= Step 4: RSA of 768 Bits ======================= M = 081CA45495AC9E0D0CBF31E0F14407ED655994EAF58B81B62C AFB5414AB6D38247616E784E18E061B0F2F7EE68CDC0DFD83B 4C0DD3A0074242FF8C978743BBDF119DA6CA3CB75955982A07 DB6C8677BC9172374C9ADA315F7F6391ED7106691D N = 87BABC043F6656A504011FF45D1F3778CEA37CFF305821CF4E D08B7F8D65CA97CE86C9B6CB045B465A69E6DF7CBAFF95CE27 2E0EF7C86EE6AC8B290F269E36DDC792F7A9C25EC607172D91 692FA39447DFEA17C4912BDFB4529F2B817849CFE5 E = 03 M ^ E mod N = 71B0DD03FE7BBC464001138000011553778983410142011006 080010EFD8DC51244CEF438241D2168FFACA2B420110460800 10B997A360E6E6AD87F8457974C06038970000000000000000 000000000000000000000000000000000000000000 Result: M = 71B0DD03FE7BBC464001138000011553778983410142011006 080010EFD8DC51244CEF438241D2168FFACA2B420110460800 10B997A360E6E6AD87F8457974C06038970000000000000000 000000000000000000000000000000000000000000 ======================= Step 5: Check Signature ======================= IDEACBC Key Signature: 0E F8 C0 AA A9 40 26 E3 97 B2 75 82 85 2F EE 77 Begin with the second block, subject this block to the algorithm IDEA by means of the Key IDEACBC. Make a XOR between this block and the calculated result obtained. Next build a new key IDEACBC, the second half happens to be the first one and the obtained calculated result becomes the second half. This way until the I finish block, for I finish we turn off the bit 7 of the first byte of the it signs if it is lit. Block 2........: 40 01 13 80 00 01 15 53 Key IDEACBC....: 0E F8 C0 AA A9 40 26 E3 97 B2 75 82 85 2F EE 77 Crypted Block..: 1B FE B6 E1 A0 C4 EE 78 (Block 2) XOR (Crypted Block): 5B FF A5 61 A0 C5 FB 2B --> Second octet new key IDEACBC New key IDEACBC: 97 B2 75 82 85 2F EE 77 5B FF A5 61 A0 C5 FB 2B Block 3........: 77 89 83 41 01 42 01 10 Key IDEACBC....: 97 B2 75 82 85 2F EE 77 5B FF A5 61 A0 C5 FB 2B Crypted Block..: 2E 60 7F B5 18 A2 6A 75 (Block 3) XOR (Crypted Block): 59 E9 FC F4 19 E0 6B 65 --> Second octet new key IDEACBC New key IDEACBC: 5B FF A5 61 A0 C5 FB 2B 59 E9 FC F4 19 E0 6B 65 Block 4........: 06 08 00 10 EF D8 DC 51 Key IDEACBC....: 5B FF A5 61 A0 C5 FB 2B 59 E9 FC F4 19 E0 6B 65 Crypted Block..: C5 88 73 18 1D 50 9A 26 (Block 4) XOR (Crypted Block): C3 80 73 08 F2 88 46 77 --> Second octet new key IDEACBC New key IDEACBC: 59 E9 FC F4 19 E0 6B 65 C3 80 73 08 F2 88 46 77 Block 5........: 24 4C EF 43 82 41 D2 16 Key IDEACBC....: 59 E9 FC F4 19 E0 6B 65 C3 80 73 08 F2 88 46 77 Crypted Block..: 68 04 5B 51 6B 40 CB 80 (Block 5) XOR (Crypted Block): 4C 48 B4 12 E9 01 19 96 --> Second octet new key IDEACBC New key IDEACBC: C3 80 73 08 F2 88 46 77 4C 48 B4 12 E9 01 19 96 Block 6........: 8F FA CA 2B 42 01 10 46 Key IDEACBC....: C3 80 73 08 F2 88 46 77 4C 48 B4 12 E9 01 19 96 Crypted Block..: 59 C7 E9 4F DB 89 46 33 (Block 6) XOR (Crypted Block): D6 3D 23 64 99 88 56 75 --> Second octet new key IDEACBC New key IDEACBC: 4C 48 B4 12 E9 01 19 96 D6 3D 23 64 99 88 56 75 Block 7........: 08 00 10 B9 97 A3 60 E6 Key IDEACBC....: 4C 48 B4 12 E9 01 19 96 D6 3D 23 64 99 88 56 75 Crypted Block..: EE 4E 38 00 C3 7E 47 5B (Block 7) XOR (Crypted Block): E6 4E 28 B9 54 DD 27 BD --> Second octet new key IDEACBC New key IDEACBC: D6 3D 23 64 99 88 56 75 E6 4E 28 B9 54 DD 27 BD Block 8........: E6 AD 87 F8 45 79 74 C0 Key IDEACBC....: D6 3D 23 64 99 88 56 75 E6 4E 28 B9 54 DD 27 BD Crypted Block..: B3 46 73 3B DC F6 8D 2E (Block 8) XOR (Crypted Block): 55 EB F4 C3 99 8F F9 EE --> Second octet new key IDEACBC New key IDEACBC: E6 4E 28 B9 54 DD 27 BD 55 EB F4 C3 99 8F F9 EE Block 9........: 60 38 97 00 00 00 00 00 Key IDEACBC....: E6 4E 28 B9 54 DD 27 BD 55 EB F4 C3 99 8F F9 EE Crypted Block..: D1 C5 4A 86 F9 17 0C AB (Block 9) XOR (Crypted Block): B1 FD DD 86 F9 17 0C AB --> Second octet new key IDEACBC New key IDEACBC: 55 EB F4 C3 99 8F F9 EE B1 FD DD 86 F9 17 0C AB Block 10........: 00 00 00 00 00 00 00 00 Key IDEACBC....: 55 EB F4 C3 99 8F F9 EE B1 FD DD 86 F9 17 0C AB Crypted Block..: 96 04 24 77 AF 96 B5 78 (Block 10) XOR (Crypted Block): 96 04 24 77 AF 96 B5 78 --> Second octet new key IDEACBC New key IDEACBC: B1 FD DD 86 F9 17 0C AB 96 04 24 77 AF 96 B5 78 Block 11........: 00 00 00 00 00 00 00 00 Key IDEACBC....: B1 FD DD 86 F9 17 0C AB 96 04 24 77 AF 96 B5 78 Crypted Block..: C2 1E 0E 2C 86 F9 D5 1E (Block 11) XOR (Crypted Block): C2 1E 0E 2C 86 F9 D5 1E --> Second octet new key IDEACBC New key IDEACBC: 96 04 24 77 AF 96 B5 78 C2 1E 0E 2C 86 F9 D5 1E Block 12........: 00 00 00 00 00 00 00 00 Key IDEACBC....: 96 04 24 77 AF 96 B5 78 C2 1E 0E 2C 86 F9 D5 1E Crypted Block..: 71 B0 DD 03 FE 7B BC 46 (Block 12) XOR (Crypted Block): 71 B0 DD 03 FE 7B BC 46 --> It signs without adjusting ======= Step 6: ======= To adjust the first byte of signature First byte of signature...: 71 (01110001 in binary) 71 AND 7F = 71 Original Signature..: 71B0DD03FE7BBC46 Calculated Signature: 71B0DD03FE7BBC46 71B0DD03FE7BBC46 Signature 4001 Provider (Digital+ (Spain)) 13800001 Creation DateStamp (01/09/2005 0:00:02) 15537789 Expiry DateStamp (12/12/2006 17:00:02) Parsing EMM Cmd 83 (Change ProvID for rest of cmd) Provider 4101 Cmd 42 (New Key Update) Data 011006080010 Data Len (16 in decimal) Idea Key 06 EFD8DC51244CEF438241D2168FFACA2B -----------> original Key in original Card IN eMU 00 & 01 Cmd 42 (New Key Update) Data 011046080010 Data Len (16 in decimal) Idea Key 46 B997A360E6E6AD87F8457974C0603897 --------> original Key in original Card IN eMU 10 & 11 FOR MORE INFO VISIT http://erluco.com/foro/