[PHP] algorithm DTC4 Nokia
<? Phpstring_to_array function ($ string){for ($ i = 0; $ i <strlen ($ string); $ i + +)$ New [$ i] = ord (substr ($ string, $ i, 1));return $ new;}
char_of function ($ string, $ pos){return ord (substr ($ string, $ pos, 1));}/ / **********************************
$ Tabla_1 = array (0x00, 0x03, 0x06, 0x01, 0x04, 0x07, 0x02, 0x05, 0x00, 0x03, 0x06, 0x01, 0x04, 0x07, 0x02, 0x05, 0x00);$ Tabla_2 = array (0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x73, 0x3B, 0x1E, 0x8E, 0x70, 0xBD, 0x86,
0x47, 0x7E, 0x24, 0x56, 0xF1, 0x77, 0x88, 0x46, 0xB1, 0xba, 0xA3, 0xB7, 0x10, 0x0A, 0xC5, 0x37,
0xC9, 0x5A, 0x28, 0xAC, 0x64, 0xA5, 0xEC, 0xAB, 0xc6, 0x67, 0x95, 0x58, 0x0D, 0xF8, 0x9A, 0xF6,
0x66, 0xDC, 0x05, 0x3d, 0xD3, 0x8A, 0xC3, 0xd8, 0x6A, 0xE9, 0x36, 0x49, 0x43, 0xBF, 0xEB, 0xD4,
0x9B, 0x68, 0xA0, 0x65, 0x5D, 0x57, 0x92, 0x1F, 0x71, 0x5C, 0xBB, 0x22, 0xC1, 0xBE, 0x7B, 0xBC,
0x63, 0x94, 0x5F, 0x2A, 0x61, 0xb8, 0x34, 0x32, 0xFD, 0xFB, 0x17, 0x40, 0xE6, 0x51, 0x1D, 0x41,
0x8F, 0x29, 0xDD, 0x04, 0x80, 0xDE, 0xE7, 0x31, 0x7F, 0x01, 0xA2, 0xF7, 0x39, 0xda, 0x6F, 0x23,
0xFE, 0x3A, 0xD0, 0x1C, 0xD1, 0x30, 0x3E, 0x12, 0xCD, 0x0F, 0xE0, 0xA8, 0xAF, 0x82, 0x59, 0x2C,
0x7D, 0xAD, 0xB2, 0xEF, 0xC2, 0x87, 0xCE, 0x75);$ Tabla_3 = array (0x01, 0x2D, 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83, 0xBC,
0xBD, 0x52, 0x1E, 0xEB, 0xAE, 0xCC, 0xD6, 0x35, 0x08, 0xC8, 0x8A, 0xB4, 0xE2, 0xCD, 0xBF, 0xD9,
0xD0, 0x50, 0x59, 0x3F, 0x4D, 0x62, 0x34, 0x0A, 0x48, 0x88, 0xB5, 0x56, 0x4C, 0x2E, 0x6B, 0x9E,
0xD2, 0x3d, 0x3C, 0x03, 0x13, 0xFB, 0x97, 0x51, 0x75, 0x4A, 0x91, 0x71, 0x23, 0xBE, 0x76, 0x2A,
0x5F, 0xF9, 0xD4, 0x55, 0x0B, 0xDC, 0x37, 0x31, 0x16, 0x74, 0xD7, 0x77, 0xA7, 0xE6, 0x07, 0xDB,
0xA4, 0x2F, 0x46, 0xF3, 0x61, 0x45, 0x67, 0xE3, 0x0C, 0xA2, 0x3B, 0x1C, 0x85, 0x18, 0x04, 0x1D,
0x29, 0xA0, 0x8F, 0xB2, 0x5A, 0xd8, 0xA6, 0x7E, 0xEE, 0x8D, 0x53, 0x4B, 0xA1, 0x9A, 0xC1, 0x0E,
0x7A, 0x49, 0xA5, 0x2C, 0x81, 0xC4, 0xC7, 0x36, 0x2B, 0x7F, 0x43, 0x95, 0x33, 0xF2, 0x6C, 0x68,
0x6D, 0xF0, 0x02, 0x28, 0xCE, 0xDD, 0x9B, 0xEA, 0x5E, 0x99, 0x7C, 0x14, 0x86, 0xCF, 0xE5, 0x42,
0xb8, 0x40, 0x78, 0x2D, 0x3A, 0xE9, 0x64, 0x1F, 0x92, 0x90, 0x7D, 0x39, 0x6F, 0xE0, 0x89, 0x30);
$ Tabla_asic2 = array (0x4A, 0x33, 0x78, 0x90, 0x11, 0xAF, 0xF2, 0x3c);$ Tabla_asic2a = array (0x30, 0x49, 0x02, 0xea, 0x6B, 0xd5, 0x88, 0x46) / / xor with 0x7A$ Tabla_asic5 = array (0x54, 0xA1, 0x3b, 0x22, 0x9d, 0xa8, 0x11, 0x77);$ Tabla_asic5a = array (0xc5, 0x30, 0xaa, 0xb3, 0x0c, 0x39, 0x80, 0xe6) / / xor with 0x91$ Tabla_asic6 = array (0x56, 0xD4, 0xD2, 0x9F, 0x9D, 0xDC, 0xEE, 0x3d);$ Tabla_asic6a = array (0xD5, 0x57, 0x51, 0x1C, 0x1E, 0x5F, 0x6D, 0xBE) / / xor with 0x83$ Tabla_asic7 = array (0x9C, 0xd7, 0xe4, 0xa9, 0xa4, 0x36, 0x72, 0x92);$ Tabla_asic7a = array (0xfd, 0xb6, 0x85, 0xc8, 0xc5, 0x57, 0x13, 0xf3) / / xor with 0x61
$ Tp1 = array (0x3F, 0x00, 0x7F, 0x20, 0x6F, 0x07, 0xFF, 0xFF);$ Tp2 = array (0x3F, 0x00, 0x7F, 0x20, 0x6F, 0x3E, 0xFF, 0xFF);$ TP3 = array (0x3F, 0x00, 0x7F, 0x20, 0x6F, 0x3F, 0xFF, 0xFF);$ TP4 = array (0x3F, 0x00, 0x7F, 0x20, 0x6F, 0x07, 0xFF, 0xFF);$ TP5 = array (0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA);$ TP6 = array (0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA);$ TP7 = array (0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA);
$ Tp_a1 = array (0xFC, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a2 = array (0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a3 = array (0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a4 = array (0x03, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a5 = array (0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a6 = array (0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a7 = array (0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
$ Tabla_op = array (1,0,0,1,1,0,0,1);$ Tabla_cambio = array (1,0,3,2,5,4,7,6,2,0,6,4,3,1,7,5,4,0,5,1,6,2,7 , 3);$ Tabla_cambio2 = array (0,1,2,3,4,5,6,7,0,2,4,6,1,3,5,7,0,4,1,5,2,6,3 , 7);
permutation function ($ string1, $ string2){global $ tabla_1;global $ tabla_2;global $ tabla_3;global $ tabla_4;global $ tabla_op;global $ tabla_cambio;global $ tabla_cambio2;
$ Aux1 = 0;
$ I = 0;
while ($ i <8) {
for ($ j = 0; $ j <8, $ j + +) {
if ($ tabla_op [$ j] == 1)
$ Str2 [$ j] = $ str2 [$ j] ^ calculation ($ aux1, $ string1); / / xor
else
$ Str2 [$ j] = ($ str2 [$ j] + calculation ($ aux1, $ string1)) & 0xFF, / / sum
$ Aux1 + +;
}
for ($ j = 0; $ j <8, $ j + +) {
if ($ tabla_op [$ j] == 1)
$ Str2 [$ j] = ($ tabla_3 [$ str2 [$ j]] + calculation ($ aux1, $ string1)) & 0xFF, / / sum
else
$ Str2 [$ j] = $ tabla_4 [$ str2 [$ j]] ^ calculation ($ aux1, $ string1); / / xor
$ Aux1 + +;
}
/ / ************************************************ ******** / /
for ($ j = 0; $ j <24, $ j + +)
$ Str2 [$ tabla_cambio [$ j]] = ($ str2 [$ tabla_cambio2 [$ j]] + $ string2 [$ tabla_cambio [$ j]]) & 0xFF;
$ Value1 = $ string2 [1];
$ Value2 = $ string2 [2];
$ Value3 = $ string2 [4];
$ String2 [1] = $ value3;
$ String2 [2] = $ value1;
$ String2 [4] = $ value2;
$ Value1 = $ string2 [3];
$ Value2 = $ string2 [5];
$ Value3 = $ string2 [6];
$ String2 [3] = $ value2;
$ String2 [5] = $ value3;
$ String2 [6] = $ value1;
$ I + +;
}
for ($ i = 0; $ i <8, $ i + +) {
$ Value1 = estimate ($ aux1, $ string1);
$ Aux1 + +;
if ($ tabla_op [$ i] == 1)
$ Str2 [$ i] = $ str2 [$ i] ^ $ value1;
else
$ Str2 [$ i] = ($ str2 [$ i] + $ value1) & 0xFF;}
return $ str2;
}
function calculate ($ string1, $ string2){global $ tabla_1;global $ tabla_2;global $ tabla_3;global $ tabla_4;
if ($ string1 <0x88) {
$ Temp2 = $ str1;
$ Temp3 = $ str2 [$ temp2 & 0x07];
$ Value1 = movimiento_bytes ($ temp2, 3);
$ Temp1 = $ tabla_1 [$ value1 & 0x1F];
$ Value2 = $ temp3;
for ($ i = 0; $ i <$ temp1, $ i + +)
$ Value2 = movimiento2_bytes ($ value2, 1);
$ Temp3 = $ value2;
$ Temp3 = temp3 + $ $ tabla_2 [$ temp2];
return $ temp3 & 0xFF;
}
else {
return 0;
}}
movimiento_bytes function ($ byte1, $ byte2){
$ Temp1 = ($ byte1 << (8 - $ byte2));
$ Temp2 = ($ byte1 >> $ byte2);
return (($ temp1 | temp2 $) & 0xFF);}
movimiento2_bytes function ($ byte1, $ byte2){
$ Temp1 = ($ byte1 >> (8 - $ byte2));
$ Temp2 = ($ byte1 << $ byte2);
return (($ temp1 | temp2 $) & 0xFF);}
xor_de_8_bytes function ($ string1, $ string2){for ($ i = 0; $ i <8, $ i + +) {$ Result [$ i] = $ str1 [$ i] ^ $ str2 [$ i];}
return $ result;}
convertir_byte_a_hex function ($ byte){
if (($ byte> 47) && ($ byte <58)) / / '0 'to '9'
return ($ byte-48);
else if (($ byte> 64) && ($ byte <71)) / / 'A' to 'F' or other character
return ($ byte-55);
else
return $ byte;}
ASCII2HEX function ($ source, $ characters){
$ J = 0;
for ($ i = 0; $ i <$ characters, $ i + = 2)
{
$ Aux1 = (convertir_byte_a_hex ($ source [$ i]) << 4);
if ($ i +1 <$ characters)
$ Aux2 = convertir_byte_a_hex ($ source [$ i +1]);
else
$ Aux2 = 0;
$ Target [$ j] = ($ aux1 | $ aux2) &0xFF;
$ J + +;
}
return $ target;}
obtener_codigo function ($ codigo_a_sacar, $ asic, $ IMEI_ASCII, $ network_code_ASCII, $ box_serial){global $ tabla_asic2;global $ tabla_asic2a;global $ tabla_asic5;global $ tabla_asic5a;global $ tabla_asic6;global $ tabla_asic6a;global $ tabla_asic7;global $ tabla_asic7a;global $ tabla_1;global $ tabla_2;global $ tabla_3;global $ tabla_4;global $ tp1;global $ tp2;global $ TP3;global $ TP4;global $ TP5;global $ TP6;global $ TP7;global $ tp_a1;global $ tp_a2;global $ tp_a3;global $ tp_a4;global $ tp_a5;global $ tp_a6;global $ tp_a7;
for ($ i = 0; $ i <strlen ($ network_code_ASCII) $ i + +) {$ Network_code [$ i] = char_of ($ network_code_ASCII, $ i);}
switch ($ asic)
{case 2:
Tabla_asic2 tabla_asic = $ $;
Tabla_asic2a tabla_asic_a = $ $;
break;
case 5:
Tabla_asic5 tabla_asic = $ $;
Tabla_asic5a tabla_asic_a = $ $;
break;
case 6:
Tabla_asic6 tabla_asic = $ $;
Tabla_asic6a tabla_asic_a = $ $;
break;
case 7:
Tabla_asic7 tabla_asic = $ $;
Tabla_asic7a tabla_asic_a = $ $;
break;
}
switch ($ codigo_a_sacar)
{case 1:$ Tabla_permutacion1_HEX = $ tp1;Tp_a1 tabla_permutacion2_HEX = $ $;
break;
case 2:$ Tabla_permutacion1_HEX = $ tp2;Tp_a2 tabla_permutacion2_HEX = $ $;
break;
case 3:$ Tabla_permutacion1_HEX = $ TP3;Tp_a3 tabla_permutacion2_HEX = $ $;
break;
case 4:$ Tabla_permutacion1_HEX = $ TP4;Tp_a4 tabla_permutacion2_HEX = $ $;
break;
case 5:$ Tabla_permutacion1_HEX = $ TP5;Tp_a5 tabla_permutacion2_HEX = $ $;
break;
case 6:TP6 tabla_permutacion1_HEX = $ $;Tp_a6 tabla_permutacion2_HEX = $ $;
break;
case 7:$ Tabla_permutacion1_HEX = $ TP7;Tp_a7 tabla_permutacion2_HEX = $ $;
break;
}
/ / Pass HEX IMEI, network code, serial box,
$ IMEI_HEX = ASCII2HEX (string_to_array ($ IMEI_ASCII), 14);
$ IMEI_HEX [7] = 0;
$ Network_code_HEX = ASCII2HEX ($ network_code, 16);
$ Box_serial_HEX = ASCII2HEX (string_to_array ($ box_serial), 6);
$ Tabla_permutacion2_HEX [7] = $ tabla_permutacion2_HEX [2];
$ Tabla_permutacion2_HEX [2] = 0;
$ Permu1 = xor_de_8_bytes ($ tabla_asic_a, $ IMEI_HEX);Tabla_permutacion1_HEX permu2 = $ $;$ Permu2 = permutation ($ permu1, $ permu2);Permu2 permu3 = $ $;$ Permu1 = xor_de_8_bytes ($ tabla_asic, $ IMEI_HEX);Tabla_permutacion2_HEX permu2 = $ $;$ Permu2 = permutation ($ permu1, $ permu2);Permu2 permu4 = $ $;$ Permu5 = xor_de_8_bytes ($ permu3, $ permu4);$ Permu1 = xor_de_8_bytes ($ tabla_asic, $ network_code_HEX);Permu5 permu2 = $ $;
$ Permu2 = permutation ($ permu1, $ permu2);
Permu2 permu6 = $ $;
$ Codigo_liberacion_HEX [0] = $ box_serial_HEX [0];
$ Codigo_liberacion_HEX [1] = $ box_serial_HEX [1];
$ Codigo_liberacion_HEX [2] = $ box_serial_HEX [2];
$ Codigo_liberacion_HEX [3] = ($ permu6 [5] & 0x77);
$ Codigo_liberacion_HEX [4] = ($ permu6 [1] & 0x77);
$ Codigo_liberacion_HEX [5] = ($ permu6 [6] & 0x77);
$ Codigo_liberacion_HEX [6] = ($ permu6 [3] & 0x77);$ Codigo_liberacion_HEX [7] = ($ permu6 [7] & 0x77);
/ / --------
for ($ i = 3; $ i <8, $ i + +)
$ Codigo_liberacion_HEX [5 + $ i] = (($ codigo_liberacion_HEX [$ i] & 0xF0) >> 4);
$ Aux [0] = $ codigo_liberacion_HEX [0] & 0x0F;
$ Aux [1] = ($ codigo_liberacion_HEX [1] & 0xF0) >> 4;
$ Aux [2] = $ codigo_liberacion_HEX [1] & 0x0F;
$ Aux [3] = ($ codigo_liberacion_HEX [2] & 0xF0) >> 4;
$ Aux [4] = $ codigo_liberacion_HEX [2] & 0x0F;
for ($ i = 0; $ i <5; $ i + +) {
if ($ aux [$ i] <= $ codigo_liberacion_HEX [8 + $ i])
$ Codigo_liberacion_HEX [8 + $ i] = $ codigo_liberacion_HEX [8 + $ i] - $ aux [$ i];
else
$ Codigo_liberacion_HEX [8 + $ i] = (10 - $ aux [$ i]) + $ codigo_liberacion_HEX [8 + $ i];
}
$ Codigo_liberacion_HEX [0] = ($ codigo_liberacion_HEX [0] & 0xF0) | $ codigo_liberacion_HEX [8];
$ Codigo_liberacion_HEX [1] = ($ codigo_liberacion_HEX [9] << 4) | $ codigo_liberacion_HEX [10];
$ Codigo_liberacion_HEX [2] = ($ codigo_liberacion_HEX [11] << 4) | $ codigo_liberacion_HEX [12];
$ Destino_codigo_liberacion [0] = chr (($ codigo_liberacion_HEX [0] & 0x0F) + 0x30);$ J = 1;for ($ i = 1; $ i <= 7; $ i + +) {$ Destino_codigo_liberacion [$ j] = chr (($ codigo_liberacion_HEX [$ i] >> 4) + 0x30);$ J + +;$ Destino_codigo_liberacion [$ j] = chr (($ codigo_liberacion_HEX [$ i] & 0x0F) + 0x30);$ J + +;}
return $ destino_codigo_liberacion;}
for ($ i = 1; $ i <8, $ i + +) {
$ Result = obtener_codigo ($ i, $ _POST [asic], $ _POST [imei], $ _POST [net], "0". $ _POST [Box]);
$ Result = implode ("", $ result);
}
?>
char_of function ($ string, $ pos){return ord (substr ($ string, $ pos, 1));}/ / **********************************
$ Tabla_1 = array (0x00, 0x03, 0x06, 0x01, 0x04, 0x07, 0x02, 0x05, 0x00, 0x03, 0x06, 0x01, 0x04, 0x07, 0x02, 0x05, 0x00);$ Tabla_2 = array (0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x73, 0x3B, 0x1E, 0x8E, 0x70, 0xBD, 0x86,
0x47, 0x7E, 0x24, 0x56, 0xF1, 0x77, 0x88, 0x46, 0xB1, 0xba, 0xA3, 0xB7, 0x10, 0x0A, 0xC5, 0x37,
0xC9, 0x5A, 0x28, 0xAC, 0x64, 0xA5, 0xEC, 0xAB, 0xc6, 0x67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 0xB2, 0x5A, 0xd8, 0xA6, 0x7E, 0xEE, 0x8D, 0x53, 0x4B, 0xA1, 0x9A, 0xC1, 0x0E,
0x7A, 0x49, 0xA5, 0x2C, 0x81, 0xC4, 0xC7, 0x36, 0x2B, 0x7F, 0x43, 0x95, 0x33, 0xF2, 0x6C, 0x68,
0x6D, 0xF0, 0x02, 0x28, 0xCE, 0xDD, 0x9B, 0xEA, 0x5E, 0x99, 0x7C, 0x14, 0x86, 0xCF, 0xE5, 0x42,
0xb8, 0x40, 0x78, 0x2D, 0x3A, 0xE9, 0x64, 0x1F, 0x92, 0x90, 0x7D, 0x39, 0x6F, 0xE0, 0x89, 0x30);
$ Tabla_asic2 = array (0x4A, 0x33, 0x78, 0x90, 0x11, 0xAF, 0xF2, 0x3c);$ Tabla_asic2a = array (0x30, 0x49, 0x02, 0xea, 0x6B, 0xd5, 0x88, 0x46) / / xor with 0x7A$ Tabla_asic5 = array (0x54, 0xA1, 0x3b, 0x22, 0x9d, 0xa8, 0x11, 0x77);$ Tabla_asic5a = array (0xc5, 0x30, 0xaa, 0xb3, 0x0c, 0x39, 0x80, 0xe6) / / xor with 0x91$ Tabla_asic6 = array (0x56, 0xD4, 0xD2, 0x9F, 0x9D, 0xDC, 0xEE, 0x3d);$ Tabla_asic6a = array (0xD5, 0x57, 0x51, 0x1C, 0x1E, 0x5F, 0x6D, 0xBE) / / xor with 0x83$ Tabla_asic7 = array (0x9C, 0xd7, 0xe4, 0xa9, 0xa4, 0x36, 0x72, 0x92);$ Tabla_asic7a = array (0xfd, 0xb6, 0x85, 0xc8, 0xc5, 0x57, 0x13, 0xf3) / / xor with 0x61
$ Tp1 = array (0x3F, 0x00, 0x7F, 0x20, 0x6F, 0x07, 0xFF, 0xFF);$ Tp2 = array (0x3F, 0x00, 0x7F, 0x20, 0x6F, 0x3E, 0xFF, 0xFF);$ TP3 = array (0x3F, 0x00, 0x7F, 0x20, 0x6F, 0x3F, 0xFF, 0xFF);$ TP4 = array (0x3F, 0x00, 0x7F, 0x20, 0x6F, 0x07, 0xFF, 0xFF);$ TP5 = array (0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA);$ TP6 = array (0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA);$ TP7 = array (0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA);
$ Tp_a1 = array (0xFC, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a2 = array (0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a3 = array (0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a4 = array (0x03, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a5 = array (0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a6 = array (0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00);$ Tp_a7 = array (0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
$ Tabla_op = array (1,0,0,1,1,0,0,1);$ Tabla_cambio = array (1,0,3,2,5,4,7,6,2,0,6,4,3,1,7,5,4,0,5,1,6,2,7 , 3);$ Tabla_cambio2 = array (0,1,2,3,4,5,6,7,0,2,4,6,1,3,5,7,0,4,1,5,2,6,3 , 7);
permutation function ($ string1, $ string2){global $ tabla_1;global $ tabla_2;global $ tabla_3;global $ tabla_4;global $ tabla_op;global $ tabla_cambio;global $ tabla_cambio2;
$ Aux1 = 0;
$ I = 0;
while ($ i <8) {
for ($ j = 0; $ j <8, $ j + +) {
if ($ tabla_op [$ j] == 1)
$ Str2 [$ j] = $ str2 [$ j] ^ calculation ($ aux1, $ string1); / / xor
else
$ Str2 [$ j] = ($ str2 [$ j] + calculation ($ aux1, $ string1)) & 0xFF, / / sum
$ Aux1 + +;
}
for ($ j = 0; $ j <8, $ j + +) {
if ($ tabla_op [$ j] == 1)
$ Str2 [$ j] = ($ tabla_3 [$ str2 [$ j]] + calculation ($ aux1, $ string1)) & 0xFF, / / sum
else
$ Str2 [$ j] = $ tabla_4 [$ str2 [$ j]] ^ calculation ($ aux1, $ string1); / / xor
$ Aux1 + +;
}
/ / ************************************************ ******** / /
for ($ j = 0; $ j <24, $ j + +)
$ Str2 [$ tabla_cambio [$ j]] = ($ str2 [$ tabla_cambio2 [$ j]] + $ string2 [$ tabla_cambio [$ j]]) & 0xFF;
$ Value1 = $ string2 [1];
$ Value2 = $ string2 [2];
$ Value3 = $ string2 [4];
$ String2 [1] = $ value3;
$ String2 [2] = $ value1;
$ String2 [4] = $ value2;
$ Value1 = $ string2 [3];
$ Value2 = $ string2 [5];
$ Value3 = $ string2 [6];
$ String2 [3] = $ value2;
$ String2 [5] = $ value3;
$ String2 [6] = $ value1;
$ I + +;
}
for ($ i = 0; $ i <8, $ i + +) {
$ Value1 = estimate ($ aux1, $ string1);
$ Aux1 + +;
if ($ tabla_op [$ i] == 1)
$ Str2 [$ i] = $ str2 [$ i] ^ $ value1;
else
$ Str2 [$ i] = ($ str2 [$ i] + $ value1) & 0xFF;}
return $ str2;
}
function calculate ($ string1, $ string2){global $ tabla_1;global $ tabla_2;global $ tabla_3;global $ tabla_4;
if ($ string1 <0x88) {
$ Temp2 = $ str1;
$ Temp3 = $ str2 [$ temp2 & 0x07];
$ Value1 = movimiento_bytes ($ temp2, 3);
$ Temp1 = $ tabla_1 [$ value1 & 0x1F];
$ Value2 = $ temp3;
for ($ i = 0; $ i <$ temp1, $ i + +)
$ Value2 = movimiento2_bytes ($ value2, 1);
$ Temp3 = $ value2;
$ Temp3 = temp3 + $ $ tabla_2 [$ temp2];
return $ temp3 & 0xFF;
}
else {
return 0;
}}
movimiento_bytes function ($ byte1, $ byte2){
$ Temp1 = ($ byte1 << (8 - $ byte2));
$ Temp2 = ($ byte1 >> $ byte2);
return (($ temp1 | temp2 $) & 0xFF);}
movimiento2_bytes function ($ byte1, $ byte2){
$ Temp1 = ($ byte1 >> (8 - $ byte2));
$ Temp2 = ($ byte1 << $ byte2);
return (($ temp1 | temp2 $) & 0xFF);}
xor_de_8_bytes function ($ string1, $ string2){for ($ i = 0; $ i <8, $ i + +) {$ Result [$ i] = $ str1 [$ i] ^ $ str2 [$ i];}
return $ result;}
convertir_byte_a_hex function ($ byte){
if (($ byte> 47) && ($ byte <58)) / / '0 'to '9'
return ($ byte-48);
else if (($ byte> 64) && ($ byte <71)) / / 'A' to 'F' or other character
return ($ byte-55);
else
return $ byte;}
ASCII2HEX function ($ source, $ characters){
$ J = 0;
for ($ i = 0; $ i <$ characters, $ i + = 2)
{
$ Aux1 = (convertir_byte_a_hex ($ source [$ i]) << 4);
if ($ i +1 <$ characters)
$ Aux2 = convertir_byte_a_hex ($ source [$ i +1]);
else
$ Aux2 = 0;
$ Target [$ j] = ($ aux1 | $ aux2) &0xFF;
$ J + +;
}
return $ target;}
obtener_codigo function ($ codigo_a_sacar, $ asic, $ IMEI_ASCII, $ network_code_ASCII, $ box_serial){global $ tabla_asic2;global $ tabla_asic2a;global $ tabla_asic5;global $ tabla_asic5a;global $ tabla_asic6;global $ tabla_asic6a;global $ tabla_asic7;global $ tabla_asic7a;global $ tabla_1;global $ tabla_2;global $ tabla_3;global $ tabla_4;global $ tp1;global $ tp2;global $ TP3;global $ TP4;global $ TP5;global $ TP6;global $ TP7;global $ tp_a1;global $ tp_a2;global $ tp_a3;global $ tp_a4;global $ tp_a5;global $ tp_a6;global $ tp_a7;
for ($ i = 0; $ i <strlen ($ network_code_ASCII) $ i + +) {$ Network_code [$ i] = char_of ($ network_code_ASCII, $ i);}
switch ($ asic)
{case 2:
Tabla_asic2 tabla_asic = $ $;
Tabla_asic2a tabla_asic_a = $ $;
break;
case 5:
Tabla_asic5 tabla_asic = $ $;
Tabla_asic5a tabla_asic_a = $ $;
break;
case 6:
Tabla_asic6 tabla_asic = $ $;
Tabla_asic6a tabla_asic_a = $ $;
break;
case 7:
Tabla_asic7 tabla_asic = $ $;
Tabla_asic7a tabla_asic_a = $ $;
break;
}
switch ($ codigo_a_sacar)
{case 1:$ Tabla_permutacion1_HEX = $ tp1;Tp_a1 tabla_permutacion2_HEX = $ $;
break;
case 2:$ Tabla_permutacion1_HEX = $ tp2;Tp_a2 tabla_permutacion2_HEX = $ $;
break;
case 3:$ Tabla_permutacion1_HEX = $ TP3;Tp_a3 tabla_permutacion2_HEX = $ $;
break;
case 4:$ Tabla_permutacion1_HEX = $ TP4;Tp_a4 tabla_permutacion2_HEX = $ $;
break;
case 5:$ Tabla_permutacion1_HEX = $ TP5;Tp_a5 tabla_permutacion2_HEX = $ $;
break;
case 6:TP6 tabla_permutacion1_HEX = $ $;Tp_a6 tabla_permutacion2_HEX = $ $;
break;
case 7:$ Tabla_permutacion1_HEX = $ TP7;Tp_a7 tabla_permutacion2_HEX = $ $;
break;
}
/ / Pass HEX IMEI, network code, serial box,
$ IMEI_HEX = ASCII2HEX (string_to_array ($ IMEI_ASCII), 14);
$ IMEI_HEX [7] = 0;
$ Network_code_HEX = ASCII2HEX ($ network_code, 16);
$ Box_serial_HEX = ASCII2HEX (string_to_array ($ box_serial), 6);
$ Tabla_permutacion2_HEX [7] = $ tabla_permutacion2_HEX [2];
$ Tabla_permutacion2_HEX [2] = 0;
$ Permu1 = xor_de_8_bytes ($ tabla_asic_a, $ IMEI_HEX);Tabla_permutacion1_HEX permu2 = $ $;$ Permu2 = permutation ($ permu1, $ permu2);Permu2 permu3 = $ $;$ Permu1 = xor_de_8_bytes ($ tabla_asic, $ IMEI_HEX);Tabla_permutacion2_HEX permu2 = $ $;$ Permu2 = permutation ($ permu1, $ permu2);Permu2 permu4 = $ $;$ Permu5 = xor_de_8_bytes ($ permu3, $ permu4);$ Permu1 = xor_de_8_bytes ($ tabla_asic, $ network_code_HEX);Permu5 permu2 = $ $;
$ Permu2 = permutation ($ permu1, $ permu2);
Permu2 permu6 = $ $;
$ Codigo_liberacion_HEX [0] = $ box_serial_HEX [0];
$ Codigo_liberacion_HEX [1] = $ box_serial_HEX [1];
$ Codigo_liberacion_HEX [2] = $ box_serial_HEX [2];
$ Codigo_liberacion_HEX [3] = ($ permu6 [5] & 0x77);
$ Codigo_liberacion_HEX [4] = ($ permu6 [1] & 0x77);
$ Codigo_liberacion_HEX [5] = ($ permu6 [6] & 0x77);
$ Codigo_liberacion_HEX [6] = ($ permu6 [3] & 0x77);$ Codigo_liberacion_HEX [7] = ($ permu6 [7] & 0x77);
/ / --------
for ($ i = 3; $ i <8, $ i + +)
$ Codigo_liberacion_HEX [5 + $ i] = (($ codigo_liberacion_HEX [$ i] & 0xF0) >> 4);
$ Aux [0] = $ codigo_liberacion_HEX [0] & 0x0F;
$ Aux [1] = ($ codigo_liberacion_HEX [1] & 0xF0) >> 4;
$ Aux [2] = $ codigo_liberacion_HEX [1] & 0x0F;
$ Aux [3] = ($ codigo_liberacion_HEX [2] & 0xF0) >> 4;
$ Aux [4] = $ codigo_liberacion_HEX [2] & 0x0F;
for ($ i = 0; $ i <5; $ i + +) {
if ($ aux [$ i] <= $ codigo_liberacion_HEX [8 + $ i])
$ Codigo_liberacion_HEX [8 + $ i] = $ codigo_liberacion_HEX [8 + $ i] - $ aux [$ i];
else
$ Codigo_liberacion_HEX [8 + $ i] = (10 - $ aux [$ i]) + $ codigo_liberacion_HEX [8 + $ i];
}
$ Codigo_liberacion_HEX [0] = ($ codigo_liberacion_HEX [0] & 0xF0) | $ codigo_liberacion_HEX [8];
$ Codigo_liberacion_HEX [1] = ($ codigo_liberacion_HEX [9] << 4) | $ codigo_liberacion_HEX [10];
$ Codigo_liberacion_HEX [2] = ($ codigo_liberacion_HEX [11] << 4) | $ codigo_liberacion_HEX [12];
$ Destino_codigo_liberacion [0] = chr (($ codigo_liberacion_HEX [0] & 0x0F) + 0x30);$ J = 1;for ($ i = 1; $ i <= 7; $ i + +) {$ Destino_codigo_liberacion [$ j] = chr (($ codigo_liberacion_HEX [$ i] >> 4) + 0x30);$ J + +;$ Destino_codigo_liberacion [$ j] = chr (($ codigo_liberacion_HEX [$ i] & 0x0F) + 0x30);$ J + +;}
return $ destino_codigo_liberacion;}
for ($ i = 1; $ i <8, $ i + +) {
$ Result = obtener_codigo ($ i, $ _POST [asic], $ _POST [imei], $ _POST [net], "0". $ _POST [Box]);
$ Result = implode ("", $ result);
}
?>
0 Response to [PHP] algorithm DTC4 Nokia
Post a Comment