Unsigned int CSSTAB0 [11] = {5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4};
Unsigned char CSSTAB1 [256] = {0x33, 0x73, 0x3b, 0x26, 0x63, 0x23, 0x6b, 0x76, 0x3e, 0x7e, 0x36, 0x2b, 0x6e, 0x2e, 0x66,0x7b, 0x06,0 x 93, 0x2 x, 0x, 0x0, 0x43, 0x03, 0x4b, 0x96, 0xDE, 0x9E, 0x0E, 0X0B, 0X4E, 0X0E, 0X46, 0X9B, 0X57, 0X17, 0X5F, 0X82, 0XC7, 0X87, 0X, 0X12, 0X5A, 0X1A, 0X52, 0X8F, 0xCA, 0x8A, 0xC2, 0X1F, 0X9, 0X99, 0X09, 0X41, 0X90, 0X09, 0X98, 0X90, 0X01, 0X48, 0X08, 0X40, 0X91, 0x3D, 0x7D, 0x35, 0X24, 0X6D, 0x2D, 0x65, 0x74, 0x3c, 0x7c, 0x34, 0x25, 0x75, 0x2c, 0x94, 0x75, 0x04, 0x4d, 0x0d, 0x45, 0x94, 0x0d, 0x9c, 0x94, 0x05, 0x4c, 0x0c, 0x44, 0x95, 0x59, 0X19, 0X51, 0X80, 0X10, 0X58, 0X18, 0X50, 0X81, 0X18, 0X88, 0XC0, 0X11, 0X47, 0X07, 0X4F, 0X92, 0X07, 0X4F, 0X92, 0X, 0x9a, 0x0a, 0x42, 0x9f, 0x53, 0x13, 0x5b, 0x86, 0x16, 0x83, 0xcb, 0x16, 0x5e, 0x1e, 0x56, 0x8b, 0xce, 0x8e, 0xc6, 0x1b, 0x, 0x, 0xF3, 0xBB, 0XA6, 0XE3, 0XA3, 0XEB, 0XF6, 0XBE, 0XFE, 0XAE, 0XAb, 0xee, 0xAe, 0x77, 0x3f, 0x22, 0x67, 0x27, 0x6f, 0x72, 0x3a, 0x7a, 0x32, 0x2f, 0x6a, 0x2a, 0x62, 0x7f, 0xa0, 0xF9, 0xa9, 0xA0, 0xE9, 0XA9, 0XE1, 0XF0, 0XB8, 0XF8, 0XA8, 0XA1, 0XE8, 0XA8, 0XE0, 0XF1, 0x5D, 0x1D, 0x55, 0x84, 0XCD, 0x8D, 0XC5, 0X14, 0X5C, 0X1C, 0X54, 0X85, 0XCC, 0X8C, 0XC4, 0X15, 0XA4, 0XFD, 0XAD, 0XA4, 0XED, 0XAD, 0XE5, 0XF4, 0XBC, 0xFC, 0xB4, 0XA5, 0XEC, 0XAC, 0X79, 0X31, 0X20, 0X69, 0X29, 0X61, 0X70, 0X38, 0X78, 0X30, 0X21, 0X68, 0X28, 0X60, 0X71, 0XB7, 0X10, 0X71, 0XB7, 0XF7, 0xBF, 0XA2, 0XE7, 0XA7, 0XEF, 0xF2, 0XBA, 0xFA, 0xB2, 0XAF, 0XEA, 0XAA, 0XE2, 0XFF};
Unsigned char csstab2 [256] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, 0x1b, 0x1a, 0x19, 0x1d, 0x1c, 0x1e, 0x1d, 0x1c, 0x27, 0 x 20, 0 x 2 x22, 0x23, 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, 0x36, 0x37, 0x33, 0x30, 0x31, 0x3f, 0x3, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x49, 0x48, 0x4b, 0x4a, 0x4d, 0x4c, 0x4f, 0x4E, 0X40, 0X41, 0X42, 0X43, 0X44, 0X45, 0X46, 0X47, 0X58, 0X5F, 0X59, 0X58, 0X5C, 0X52, 0X53, 0X50, 0X51, 0X56, 0X57, 0X54, 0X55, 0x6d, 0x6c, 0x6f, 0x6b, 0x6a, 0x64, 0x65, 0x66, 0x67, 0x60, 0x61, 0x62, 0x63, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78, 0x76, 0x77, 0x74, 0x75, 0x72, 0x73, 0x70, 0x71, 0x92, 0x93, 0x90, 0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, 0X49 , 0x6d, 0x92,0x00,0x24,0x49,0x6d, 0x92,0x/6,0 xdb, 0xff, 0x00, 0x24,0x49,0x6d, 0x92,0x00,0x24,0x49,0x6d 0x92, 0x00, 0x24, 0x49, 0x6d, 0x92, 0x/6, 0x249, 0x6d, 0x92, 0x49, 0x6d, 0x92, 0x24, 0x49, 0x00, 0x24, 0x49, 0x6d, 0x92 , 0xB6, 0x24, 0x49, 0x6D, 0x92, 0xB6, 0xDB, 0xFF, 0x00, 0X24, 0X49, 0X6D, 0X92, 0X24, 0X49, 0X00, 0X24, 0X49, 0X6D, 0X92, 0XB6 , 0x24, 0x49, 0x6d, 0x92, 0x/6, 0xDB, 0xFF, 0x00, 0x24, 0x49, 0X6D, 0x92, 0X00, 0X24, 0X49, 0X6D, 0X92, 0X6, 0xDB 0xFF, 0x00, 0x24, 0x49, 0x6d, 0x92, 0x/0x24,0x49,0x6d, 0x92,0x/6,0 xdb, 0xff, 0x00, 0x24, 0x49, 0x6d, 0x92,0 XB6, 0x24, 0x49, 0x6D, 0x92, 0X249, 0X49, 0X00, 0X24, 0X49, 0X6D, 0X92, 0X00, 0X24, 0X49, 0X6D, 0X92, 0XB6, 0xDB, 0xFF, 0x00, 0x24, 0x49, 0x6d, 0x92, 0x/6, 0x249, 0x6d, 0x92, 0x/6, 0x24, 0xff, 0x00, 0x24, 0x49, 0x6d, 0x92, 0xB6, 0xDB, 0xFF, 0x00, 0X24, 0X49, 0X6D, 0x92, 0x00, 0x24, 0x49, 0X6D, 0x92, 0X24, 0X49, 0X00, 0X24, 0X49, 0X6D, 0x92, 0XB6, 0X, 0xFF, 0x00, 0x24, 0x49, 0x6d, 0x92, 0xB6, 0xDB, 0xFF, 0x00, 0X24, 0X49, 0X6D, 0X92, 0X24, 0X49, 0X6D, 0X92, 0X249, 0X6D, 0x92, 0X00, 0X, 0xFF, 0x00, 0x24, 0x49, 0x6d, 0x92, 0x24,0x49,0x6d, 0x92,0x00,0x24,0x49,0x6d, 0x92,0 x /,0 xdb, 0xff, 0x00, 0x24, 0x49, 0x6d, 0x92, 0xB6, 0xDB, 0xFF, 0x00, 0X24, 0X49, 0X6D, 0x92, 0X00, 0X24, 0X49, 0X6D, 0x92, 0X6, 0X6D, 0x92, 0XB6, 0xDB, 0xFF, 0x00,
0x24, 0x49, 0x6d, 0x92, 0x24,0x49,0x6d, 0x92,0x00,0x24,0x49,0x6d, 0x92,0 x /,0 xdb, 0xff, 0x00, 0x24, 0x49, 0x6d, 0x92, 0x00, 0x24, 0x49, 0x6d, 0x92, 0x00, 0x24, 0x49, 0x6d, 0x92, 0x, 0x24, 0xFF, 0x00, 0x24, 0x49, 0x6d, 0x92, 0xB6, 0x24, 0x49, 0x6d, 0x92, 0x/6, 0x29, 0x00, 0x24, 0x49, 0x6d, 0x92, 0x/6, 0x24, 0xFF, 0x00, 0x24, 0x49, 0x6d, 0x92, 0x00, 0x24, 0x49, 0x6d, 0x92, 0x/0x24,0x49,0x6d, 0x92,0x24,0x6d, 0x92,0 x24, 0x49,0x00,04,0x49,0x6d, 0x92, 0xB6, 0X24, 0X49, 0X6D, 0x92, 0XB6, 0X249, 0X00, 0X24, 0X49, 0X6D, 0X92, 0X24, 0X49, 0X00, 0X24, 0X49, 0X6D, 0X92, 0X6, 0xDB, 0xFF, 0x00, 0x24, 0x49, 0x6d, 0x92, 0x/6, 0x249, 0x6d, 0x92, 0x/6, 0x24, 0xff, 0x00, 0x24, 0x49, 0x6d, 0x92, 0xB6, 0xDB, 0xFF, 0x00, 0X24, 0X49, 0X6D, 0x92, 0X00, 0X24, 0X49, 0X6D, 0X92, 0XB6, 0xDB, 0xFF};
Unsigned char csstab4 [256] = {0x00, 0x80, 0X40, 0X60, 0X10, 0X10, 0X90, 0X50, 0X0, 0X30, 0xB0, 0X70, 0XF0, 0x08, 0X88, 0X48, 0XC8, 0X28, 0xA8, 0X68, 0X58, 0X18, 0X38, 0X58, 0X78, 0X44, 0X04, 0X84, 0X44, 0X64, 0X24, 0XA4, 0X64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, 0x02, 0xFc, 0x7c, 0xBc, 0x3c, 0x1c, 0x5c, 0x9c, 0x1c, 0x2c, 0x6c, 0x4c, 0x2c, 0x0c, 0x4c, 0x8c, 0x0c, 0x1, 0x74, 0xB4, 0X34, 0X14, 0X54, 0X94, 0X14, 0XE4, 0x64, 0XA4, 0X24, 0X04, 0X44, 0X84, 0X04, 0X38, 0X78, 0X58, 0X98, 0X18, 0X28, 0X68, 0XA8, 0X28, 0X08, 0X48, 0X88, 0X08, 0XF0, 0X70, 0x50, 0X30, 0X10, 0X50, 0X60, 0XA0, 0X20, 0X20, 0X40, 0X80, 0X00}; void cssdescRamble (unsigned char * sec, unsigned char * key) {unsigned int T2, T3 , T4, T5, T6; Unsigned char * end = sec 0x800;
t1 = key [0] ^ sec [0x54] | 0x100; t2 = key [1] ^ sec [0x55]; t3 = (* ((unsigned int *) (key 2))) ^ (* ((unsigned int *) (SEC 0X56)))))); T4 = T3 & 7; T3 = T3 * 2 8-T4; SEC = 0x80; T5 = 0; while (sec! = end) {T4 = CSSTAB2 [T2] ^ CSSTAB3 [T1 ]; T2 = T1 >> 1; T1 = ((T1 & 1) << 8) ^ T4; T4 = CSSTAB5 [T4]; T6 = ((((((((((((((((t3 >> 3) ^ T3) >> 1) ^ T3) >> 8) ^ T3) >> 5) & 0xFF; T3 = (T3 << 8) | T6; T6 = CSSTAB4 [T6]; T5 = T6 T4; * sec = csstab1 [* sec] ^ T5 & 0xFF); T5 >> = 8;}} Void CsstitleKey1 (unsigned char * iM) {UNSIGNED INT T2, T2, T3, T4, T5, T6; UNSIGNED CHAR K [5]; int 1;
T1 = IM [0] | 0x100; T2 = IM [1]; T3 = * ((unsigned int *)); T4 = T3 & 7; T3 = T3 * 2 8-T4; T5 = 0; For (i = 0; i <5; i ) {T4 = CSSTAB2 [T2] ^ CSSTAB3 [T1]; T2 = T1 >> 1; T1 = ((T1 & 1) << 8) ^ T4; T4 = CSSTAB4 [T4 ]; T6 = (((((((((((((T3 >> 3) ^ T3) >> 8) ^ T3) >> 5) & 0xFF; T3 = (T3 << 8) | T6; T6 = CSSTAB4 [T6]; T5 = T6 T4; K [I] = T5 & 0xFF; T5 >> = 8;} for (i = 9; i> = 0; I - KEY [CSSTAB0 [i 1] ] = K [CSSTAB0 [i 1]] ^ CSSTAB1 [Key [CSSTAB0 [i 1]]] ^ Key [CSSTAB0 [I]];
Void CsstitleKey2 (unsigned char * iM) {UNSIGNED INT T2, T2, T3, T4, T5, T6; Unsigned Char K [5]; int 1;
T1 = IM [0] | 0x100; T2 = IM [1]; T3 = * ((unsigned int *)); T4 = T3 & 7; T3 = T3 * 2 8-T4; T5 = 0; For (i = 0; i <5; i ) {T4 = CSSTAB2 [T2] ^ CSSTAB3 [T1]; T2 = T1 >> 1; T1 = ((T1 & 1) << 8) ^ T4; T4 = CSSTAB4 [T4 ]; T6 = (((((((((((((T3 >> 3) ^ T3) >> 8) ^ T3) >> 5) & 0xFF; T3 = (T3 << 8) | T6; T6 = CSSTAB5 [T6]; T5 = T6 T4; K [I] = T5 & 0xFF; T5 >> = 8;} for (i = 9; I> = 0; I - KEY [CSSTAB0 [i 1] ] = K [CSSTAB0 [i 1]] ^ CSSTAB1 [Key [CSSTAB0 [i 1]]] ^ Key [csstab0 [i]];} void cssdecrypttitlekey (unsigned char * tkey, unsigned char * dkey) {INT i Unsigned char IM1 [6]; unsigned char = = {0x51, 0x67, 0x67, 0xc5, 0xe0, 0x00}; for (i = 0; i <6; i ) IM1 [i] = DKEY [i] ;
CsstitleKey1 (IM1, IM2); CSstitleKey2 (TKEY, IM1);}