Cleaned up everything except MakeKeyFromBlock()

This commit is contained in:
2019-02-21 13:34:08 -06:00
parent fa550d073e
commit b1cb846420

View File

@ -1,18 +1,13 @@
using System; namespace ScreenLogicConnect
namespace ScreenLogicConnect
{ {
public class HLEncoder public class HLEncoder
{ {
private readonly int BLOCK_SIZE = 16; private const int BLOCK_SIZE = 16;
private readonly int[,] Kd = new int[15, 8]; private const int MAX_KC = 8;
private readonly int[,] Ke = new int[15, 8]; private const int MAX_ROUNDS = 14;
//private int MAX_BC = 8;
private readonly int MAX_KC = 8; private readonly int[,] Kd = new int[MAX_ROUNDS + 1, MAX_KC];
private readonly int MAX_ROUNDS = 14; private readonly int[,] Ke = new int[MAX_ROUNDS + 1, MAX_KC];
readonly int[] a = new int[8];
private bool bKeyInit;
int iROUNDS;
private readonly byte[] sm_S = new byte[] { 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x1, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x4, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x5, 0x9a, 0x7, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 0x9, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x0, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x2, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0xc, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0xb, 0xdb, 0xe0, 0x32, 0x3a, 0xa, 0x49, 0x6, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x8, 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x3, 0xf6, 0xe, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0xd, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0xf, 0xb0, 0x54, 0xbb, 0x16 }; private readonly byte[] sm_S = new byte[] { 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x1, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x4, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x5, 0x9a, 0x7, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 0x9, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x0, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x2, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0xc, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0xb, 0xdb, 0xe0, 0x32, 0x3a, 0xa, 0x49, 0x6, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x8, 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x3, 0xf6, 0xe, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0xd, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0xf, 0xb0, 0x54, 0xbb, 0x16 };
private readonly int[] sm_T1 = new int[] { -966564955, -126059388, -294160487, -159679603, -855539, -697603139, -563122255, -1849309868, 1613770832, 33620227, -832084055, 1445669757, -402719207, -1244145822, 1303096294, -327780710, -1882535355, 528646813, -1983264448, -92439161, -268764651, -1302767125, -1907931191, -68095989, 1101901292, -1277897625, 1604494077, 1169141738, 597466303, 1403299063, -462261610, -1681866661, 1974974402, -503448292, 1033081774, 1277568618, 1815492186, 2118074177, -168298750, -2083730353, 1748251740, 1369810420, -773462732, -101584632, -495881837, -1411852173, 1647391059, 706024767, 134480908, -1782069422, 1176707941, -1648114850, 806885416, 932615841, 168101135, 798661301, 235341577, 605164086, 461406363, -538779075, -840176858, 1311188841, 2142417613, -361400929, 302582043, 495158174, 1479289972, 874125870, 907746093, -596742478, -1269146898, 1537253627, -1538108682, 1983593293, -1210657183, 2108928974, 1378429307, -572267714, 1580150641, 327451799, -1504488459, -1177431704, 0, -1041371860, 1075847264, -469959649, 2041688520, -1235526675, -731223362, -1916023994, 1740553945, 1916352843, -1807070498, -1739830060, -1336387352, -2049978550, -1143943061, -974131414, 1336584933, -302253290, -2042412091, -1706209833, 1714631509, 293963156, -1975171633, -369493744, 67240454, -25198719, -1605349136, 2017213508, 631218106, 1269344483, -1571728909, 1571005438, -2143272768, 93294474, 1066570413, 563977660, 1882732616, -235539196, 1673313503, 2008463041, -1344611723, 1109467491, 537923632, -436207846, -34344178, -1076702611, -2117218996, 403442708, 638784309, -1007883217, -1101045791, 899127202, -2008791860, 773265209, -1815821225, 1437050866, -58818942, 2050833735, -932944724, -1168286233, 840505643, -428641387, -1067425632, 427917720, -1638969391, -1545806721, 1143087718, 1412049534, 999329963, 193497219, -1941551414, -940642775, 1807268051, 672404540, -1478566279, -1134666014, 369822493, -1378100362, -606019525, 1681011286, 1949973070, 336202270, -1840690725, 201721354, 1210328172, -1201906460, -1614626211, -1110191250, 1135389935, -1000185178, 965841320, 831886756, -739974089, -226920053, -706222286, -1949775805, 1849112409, -630362697, 26054028, -1311386268, -1672589614, 1235855840, -663982924, -1403627782, -202050553, -806688219, -899324497, -193299826, 1202630377, 268961816, 1874508501, -260540280, 1243948399, 1546530418, 941366308, 1470539505, 1941222599, -1748580783, -873928669, -1579295364, -395021156, 1042226977, -1773450275, 1639824860, 227249030, 260737669, -529502064, 2084453954, 1907733956, -865704278, -1874310952, 100860677, -134810111, 470683154, -1033805405, 1781871967, -1370007559, 1773779408, 394692241, -1715355304, 974986535, 664706745, -639508168, -336005101, 731420851, 571543859, -764843589, -1445340816, 126783113, 865375399, 765172662, 1008606754, 361203602, -907417312, -2016489911, -1437248001, 1344809080, -1512054918, 59542671, 1503764984, 160008576, 437062935, 1707065306, -672733647, -2076032314, -798463816, -2109652541, 697932208, 1512910199, 504303377, 2075177163, -1470868228, 1841019862, 739644986 }; private readonly int[] sm_T1 = new int[] { -966564955, -126059388, -294160487, -159679603, -855539, -697603139, -563122255, -1849309868, 1613770832, 33620227, -832084055, 1445669757, -402719207, -1244145822, 1303096294, -327780710, -1882535355, 528646813, -1983264448, -92439161, -268764651, -1302767125, -1907931191, -68095989, 1101901292, -1277897625, 1604494077, 1169141738, 597466303, 1403299063, -462261610, -1681866661, 1974974402, -503448292, 1033081774, 1277568618, 1815492186, 2118074177, -168298750, -2083730353, 1748251740, 1369810420, -773462732, -101584632, -495881837, -1411852173, 1647391059, 706024767, 134480908, -1782069422, 1176707941, -1648114850, 806885416, 932615841, 168101135, 798661301, 235341577, 605164086, 461406363, -538779075, -840176858, 1311188841, 2142417613, -361400929, 302582043, 495158174, 1479289972, 874125870, 907746093, -596742478, -1269146898, 1537253627, -1538108682, 1983593293, -1210657183, 2108928974, 1378429307, -572267714, 1580150641, 327451799, -1504488459, -1177431704, 0, -1041371860, 1075847264, -469959649, 2041688520, -1235526675, -731223362, -1916023994, 1740553945, 1916352843, -1807070498, -1739830060, -1336387352, -2049978550, -1143943061, -974131414, 1336584933, -302253290, -2042412091, -1706209833, 1714631509, 293963156, -1975171633, -369493744, 67240454, -25198719, -1605349136, 2017213508, 631218106, 1269344483, -1571728909, 1571005438, -2143272768, 93294474, 1066570413, 563977660, 1882732616, -235539196, 1673313503, 2008463041, -1344611723, 1109467491, 537923632, -436207846, -34344178, -1076702611, -2117218996, 403442708, 638784309, -1007883217, -1101045791, 899127202, -2008791860, 773265209, -1815821225, 1437050866, -58818942, 2050833735, -932944724, -1168286233, 840505643, -428641387, -1067425632, 427917720, -1638969391, -1545806721, 1143087718, 1412049534, 999329963, 193497219, -1941551414, -940642775, 1807268051, 672404540, -1478566279, -1134666014, 369822493, -1378100362, -606019525, 1681011286, 1949973070, 336202270, -1840690725, 201721354, 1210328172, -1201906460, -1614626211, -1110191250, 1135389935, -1000185178, 965841320, 831886756, -739974089, -226920053, -706222286, -1949775805, 1849112409, -630362697, 26054028, -1311386268, -1672589614, 1235855840, -663982924, -1403627782, -202050553, -806688219, -899324497, -193299826, 1202630377, 268961816, 1874508501, -260540280, 1243948399, 1546530418, 941366308, 1470539505, 1941222599, -1748580783, -873928669, -1579295364, -395021156, 1042226977, -1773450275, 1639824860, 227249030, 260737669, -529502064, 2084453954, 1907733956, -865704278, -1874310952, 100860677, -134810111, 470683154, -1033805405, 1781871967, -1370007559, 1773779408, 394692241, -1715355304, 974986535, 664706745, -639508168, -336005101, 731420851, 571543859, -764843589, -1445340816, 126783113, 865375399, 765172662, 1008606754, 361203602, -907417312, -2016489911, -1437248001, 1344809080, -1512054918, 59542671, 1503764984, 160008576, 437062935, 1707065306, -672733647, -2076032314, -798463816, -2109652541, 697932208, 1512910199, 504303377, 2075177163, -1470868228, 1841019862, 739644986 };
private readonly int[] sm_T2 = new int[] { -1513725085, -2064089988, -1712425097, -1913226373, 234877682, -1110021269, -1310822545, 1418839493, 1348481072, 50462977, -1446090905, 2102799147, 434634494, 1656084439, -431117397, -1695779210, 1167051466, -1658879358, 1082771913, -2013627011, 368048890, -340633255, -913422521, 201060592, -331240019, 1739838676, -44064094, -364531793, -1088185188, -145513308, -1763413390, 1536934080, -1032472649, 484572669, -1371696237, 1783375398, 1517041206, 1098792767, 49674231, 1334037708, 1550332980, -195975771, 886171109, 150598129, -1813876367, 1940642008, 1398944049, 1059722517, 201851908, 1385547719, 1699095331, 1587397571, 674240536, -1590192490, 252314885, -1255171430, 151914247, 908333586, -1692696448, 1038082786, 651029483, 1766729511, -847269198, -1612024459, 454166793, -1642232957, 1951935532, 775166490, 758520603, -1294176658, -290170278, -77881184, -157003182, 1299594043, 1639438038, -830622797, 2068982057, 1054729187, 1901997871, -1760328572, -173649069, 1757008337, 0, 750906861, 1614815264, 535035132, -931548751, -306816165, -1093375382, 1183697867, -647512386, 1265776953, -560706998, -728216500, -391096232, 1250283471, 1807470800, 717615087, -447763798, 384695291, -981056701, -677753523, 1432761139, -1810791035, -813021883, 283769337, 100925954, -2114027649, -257929136, 1148730428, -1171939425, -481580888, -207466159, -27417693, -1065336768, -1979347057, -1388342638, -1138647651, 1215313976, 82966005, -547111748, -1049119050, 1974459098, 1665278241, 807407632, 451280895, 251524083, 1841287890, 1283575245, 337120268, 891687699, 801369324, -507617441, -1573546089, -863484860, 959321879, 1469301956, -229267545, -2097381762, 1199193405, -1396153244, -407216803, 724703513, -1780059277, -1598005152, -1743158911, -778154161, 2141445340, 1715741218, 2119445034, -1422159728, -2096396152, -896776634, 700968686, -747915080, 1009259540, 2041044702, -490971554, 487983883, 1991105499, 1004265696, 1449407026, 1316239930, 504629770, -611169975, 168560134, 1816667172, -457679780, 1570751170, 1857934291, -280777556, -1497079198, -1472622191, -1540254315, 936633572, -1947043463, 852879335, 1133234376, 1500395319, -1210421907, -1946055283, 1689376213, -761508274, -532043351, -1260884884, -89369002, 133428468, 634383082, -1345690267, -1896580486, -381178194, 403703816, -714097990, -1997506440, 1867130149, 1918643758, 607656988, -245913946, -948718412, 1368901318, 600565992, 2090982877, -1662487436, 557719327, -577352885, -597574211, -2045932661, -2062579062, -1864339344, 1115438654, -999180875, -1429445018, -661632952, 84280067, 33027830, 303828494, -1547542175, 1600795957, -106014889, -798377543, -1860729210, 1486471617, 658119965, -1188585826, 953803233, 334231800, -1288988520, 857870609, -1143838359, 1890179545, -1995993458, -1489791852, -1238525029, 574365214, -1844082809, 550103529, 1233637070, -5614251, 2018519080, 2057691103, -1895592820, -128343647, -2146858615, 387583245, -630865985, 836232934, -964410814, -1194301336, -1014873791, -1339450983, 2002398509, 287182607, -881086288, -56077228, -697451589, 975967766 }; private readonly int[] sm_T2 = new int[] { -1513725085, -2064089988, -1712425097, -1913226373, 234877682, -1110021269, -1310822545, 1418839493, 1348481072, 50462977, -1446090905, 2102799147, 434634494, 1656084439, -431117397, -1695779210, 1167051466, -1658879358, 1082771913, -2013627011, 368048890, -340633255, -913422521, 201060592, -331240019, 1739838676, -44064094, -364531793, -1088185188, -145513308, -1763413390, 1536934080, -1032472649, 484572669, -1371696237, 1783375398, 1517041206, 1098792767, 49674231, 1334037708, 1550332980, -195975771, 886171109, 150598129, -1813876367, 1940642008, 1398944049, 1059722517, 201851908, 1385547719, 1699095331, 1587397571, 674240536, -1590192490, 252314885, -1255171430, 151914247, 908333586, -1692696448, 1038082786, 651029483, 1766729511, -847269198, -1612024459, 454166793, -1642232957, 1951935532, 775166490, 758520603, -1294176658, -290170278, -77881184, -157003182, 1299594043, 1639438038, -830622797, 2068982057, 1054729187, 1901997871, -1760328572, -173649069, 1757008337, 0, 750906861, 1614815264, 535035132, -931548751, -306816165, -1093375382, 1183697867, -647512386, 1265776953, -560706998, -728216500, -391096232, 1250283471, 1807470800, 717615087, -447763798, 384695291, -981056701, -677753523, 1432761139, -1810791035, -813021883, 283769337, 100925954, -2114027649, -257929136, 1148730428, -1171939425, -481580888, -207466159, -27417693, -1065336768, -1979347057, -1388342638, -1138647651, 1215313976, 82966005, -547111748, -1049119050, 1974459098, 1665278241, 807407632, 451280895, 251524083, 1841287890, 1283575245, 337120268, 891687699, 801369324, -507617441, -1573546089, -863484860, 959321879, 1469301956, -229267545, -2097381762, 1199193405, -1396153244, -407216803, 724703513, -1780059277, -1598005152, -1743158911, -778154161, 2141445340, 1715741218, 2119445034, -1422159728, -2096396152, -896776634, 700968686, -747915080, 1009259540, 2041044702, -490971554, 487983883, 1991105499, 1004265696, 1449407026, 1316239930, 504629770, -611169975, 168560134, 1816667172, -457679780, 1570751170, 1857934291, -280777556, -1497079198, -1472622191, -1540254315, 936633572, -1947043463, 852879335, 1133234376, 1500395319, -1210421907, -1946055283, 1689376213, -761508274, -532043351, -1260884884, -89369002, 133428468, 634383082, -1345690267, -1896580486, -381178194, 403703816, -714097990, -1997506440, 1867130149, 1918643758, 607656988, -245913946, -948718412, 1368901318, 600565992, 2090982877, -1662487436, 557719327, -577352885, -597574211, -2045932661, -2062579062, -1864339344, 1115438654, -999180875, -1429445018, -661632952, 84280067, 33027830, 303828494, -1547542175, 1600795957, -106014889, -798377543, -1860729210, 1486471617, 658119965, -1188585826, 953803233, 334231800, -1288988520, 857870609, -1143838359, 1890179545, -1995993458, -1489791852, -1238525029, 574365214, -1844082809, 550103529, 1233637070, -5614251, 2018519080, 2057691103, -1895592820, -128343647, -2146858615, 387583245, -630865985, 836232934, -964410814, -1194301336, -1014873791, -1339450983, 2002398509, 287182607, -881086288, -56077228, -697451589, 975967766 };
@ -23,8 +18,10 @@ namespace ScreenLogicConnect
private readonly int[] sm_U3 = new int[] { 0, 218828297, 437656594, 387781147, 875313188, 958871085, 775562294, 590424639, 1750626376, 1699970625, 1917742170, 2135253587, 1551124588, 1367295589, 1180849278, 1265195639, -793714544, -574886247, -895026046, -944901493, -459482956, -375925059, -24460122, -209597777, -1192718120, -1243373871, -1560376118, -1342864701, -1933268740, -2117097739, -1764576018, -1680229657, -1149510853, -1234119374, -1586641111, -1402549984, -1890065633, -2107839210, -1790836979, -1739919100, -752637069, -567761542, -919226527, -1002522264, -418409641, -368796322, -48656571, -267222708, 1808481195, 1723872674, 1910319033, 2094410160, 1608975247, 1391201670, 1173430173, 1224348052, 59984867, 244860394, 428169201, 344873464, 935293895, 984907214, 766078933, 547512796, 1844882806, 1627235199, 2011214180, 2062270317, 1507497298, 1423022939, 1137477952, 1321699145, 95345982, 145085239, 532201772, 313773861, 830661914, 1015671571, 731183368, 648017665, -1119466010, -1337113617, -1487908364, -1436852227, -1989511742, -2073986101, -1820562992, -1636341799, -719438418, -669699161, -821550660, -1039978571, -516815478, -331805821, -81520232, -164685935, -695372211, -611944380, -862229921, -1047501738, -492745111, -274055072, -122203525, -172204942, -1093335547, -1277294580, -1530717673, -1446505442, -1963377119, -2014171096, -1863376333, -1645990854, 104699613, 188127444, 472615631, 287343814, 840019705, 1058709744, 671593195, 621591778, 1852171925, 1668212892, 1953757831, 2037970062, 1514790577, 1463996600, 1080017571, 1297403050, -621329940, -671330331, -1058972162, -840281097, -287606328, -472877119, -187865638, -104436781, -1297141340, -1079754835, -1464259146, -1515052097, -2038232704, -1954019447, -1667951214, -1851909221, 172466556, 122466165, 273792366, 492483431, 1047239000, 861968209, 612205898, 695634755, 1646252340, 1863638845, 2013908262, 1963115311, 1446242576, 1530455833, 1277555970, 1093597963, 1636604631, 1820824798, 2073724613, 1989249228, 1436590835, 1487645946, 1337376481, 1119727848, 164948639, 81781910, 331544205, 516552836, 1039717051, 821288114, 669961897, 719700128, -1321436601, -1137216434, -1423284651, -1507760036, -2062531997, -2011476886, -1626972559, -1844621192, -647755249, -730921978, -1015933411, -830924780, -314035669, -532464606, -144822727, -95084496, -1224610662, -1173691757, -1390940024, -1608712575, -2094148418, -1910056265, -1724135252, -1808742747, -547775278, -766340389, -984645440, -935031095, -344611594, -427906305, -245122844, -60246291, 1739656202, 1790575107, 2108100632, 1890328081, 1402811438, 1586903591, 1233856572, 1149249077, 266959938, 48394827, 369057872, 418672217, 1002783846, 919489135, 567498868, 752375421, 209336225, 24197544, 376187827, 459744698, 945164165, 895287692, 574624663, 793451934, 1679968233, 1764313568, 2117360635, 1933530610, 1343127501, 1560637892, 1243112415, 1192455638, -590686415, -775825096, -958608605, -875051734, -387518699, -437395172, -219090169, -262898, -1265457287, -1181111952, -1367032981, -1550863006, -2134991011, -1917480620, -1700232369, -1750889146 }; private readonly int[] sm_U3 = new int[] { 0, 218828297, 437656594, 387781147, 875313188, 958871085, 775562294, 590424639, 1750626376, 1699970625, 1917742170, 2135253587, 1551124588, 1367295589, 1180849278, 1265195639, -793714544, -574886247, -895026046, -944901493, -459482956, -375925059, -24460122, -209597777, -1192718120, -1243373871, -1560376118, -1342864701, -1933268740, -2117097739, -1764576018, -1680229657, -1149510853, -1234119374, -1586641111, -1402549984, -1890065633, -2107839210, -1790836979, -1739919100, -752637069, -567761542, -919226527, -1002522264, -418409641, -368796322, -48656571, -267222708, 1808481195, 1723872674, 1910319033, 2094410160, 1608975247, 1391201670, 1173430173, 1224348052, 59984867, 244860394, 428169201, 344873464, 935293895, 984907214, 766078933, 547512796, 1844882806, 1627235199, 2011214180, 2062270317, 1507497298, 1423022939, 1137477952, 1321699145, 95345982, 145085239, 532201772, 313773861, 830661914, 1015671571, 731183368, 648017665, -1119466010, -1337113617, -1487908364, -1436852227, -1989511742, -2073986101, -1820562992, -1636341799, -719438418, -669699161, -821550660, -1039978571, -516815478, -331805821, -81520232, -164685935, -695372211, -611944380, -862229921, -1047501738, -492745111, -274055072, -122203525, -172204942, -1093335547, -1277294580, -1530717673, -1446505442, -1963377119, -2014171096, -1863376333, -1645990854, 104699613, 188127444, 472615631, 287343814, 840019705, 1058709744, 671593195, 621591778, 1852171925, 1668212892, 1953757831, 2037970062, 1514790577, 1463996600, 1080017571, 1297403050, -621329940, -671330331, -1058972162, -840281097, -287606328, -472877119, -187865638, -104436781, -1297141340, -1079754835, -1464259146, -1515052097, -2038232704, -1954019447, -1667951214, -1851909221, 172466556, 122466165, 273792366, 492483431, 1047239000, 861968209, 612205898, 695634755, 1646252340, 1863638845, 2013908262, 1963115311, 1446242576, 1530455833, 1277555970, 1093597963, 1636604631, 1820824798, 2073724613, 1989249228, 1436590835, 1487645946, 1337376481, 1119727848, 164948639, 81781910, 331544205, 516552836, 1039717051, 821288114, 669961897, 719700128, -1321436601, -1137216434, -1423284651, -1507760036, -2062531997, -2011476886, -1626972559, -1844621192, -647755249, -730921978, -1015933411, -830924780, -314035669, -532464606, -144822727, -95084496, -1224610662, -1173691757, -1390940024, -1608712575, -2094148418, -1910056265, -1724135252, -1808742747, -547775278, -766340389, -984645440, -935031095, -344611594, -427906305, -245122844, -60246291, 1739656202, 1790575107, 2108100632, 1890328081, 1402811438, 1586903591, 1233856572, 1149249077, 266959938, 48394827, 369057872, 418672217, 1002783846, 919489135, 567498868, 752375421, 209336225, 24197544, 376187827, 459744698, 945164165, 895287692, 574624663, 793451934, 1679968233, 1764313568, 2117360635, 1933530610, 1343127501, 1560637892, 1243112415, 1192455638, -590686415, -775825096, -958608605, -875051734, -387518699, -437395172, -219090169, -262898, -1265457287, -1181111952, -1367032981, -1550863006, -2134991011, -1917480620, -1700232369, -1750889146 };
private readonly int[] sm_U4 = new int[] { 0, 151849742, 303699484, 454499602, 607398968, 758720310, 908999204, 1059270954, 1214797936, 1097159550, 1517440620, 1400849762, 1817998408, 1699839814, 2118541908, 2001430874, -1865371424, -1713521682, -2100648196, -1949848078, -1260086056, -1108764714, -1493267772, -1342996022, -658970480, -776608866, -895287668, -1011878526, -57883480, -176042074, -292105548, -409216582, 1002142683, 850817237, 698445255, 548169417, 529487843, 377642221, 227885567, 77089521, 1943217067, 2061379749, 1640576439, 1757691577, 1474760595, 1592394909, 1174215055, 1290801793, -1418998981, -1570324427, -1183720153, -1333995991, -1889540349, -2041385971, -1656360673, -1807156719, -486304949, -368142267, -249985705, -132870567, -952647821, -835013507, -718427793, -601841055, 1986918061, 2137062819, 1685577905, 1836772287, 1381620373, 1532285339, 1078185097, 1229899655, 1040559837, 923313619, 740276417, 621982671, 439452389, 322734571, 137073913, 19308535, -423803315, -273658557, -190361519, -39167137, -1031181707, -880516741, -795640727, -643926169, -1361764803, -1479011021, -1127282655, -1245576401, -1964953083, -2081670901, -1728371687, -1846137065, 1305906550, 1155237496, 1607244650, 1455525988, 1776460110, 1626319424, 2079897426, 1928707164, 96392454, 213114376, 396673818, 514443284, 562755902, 679998000, 865136418, 983426092, -586793578, -737462632, -820237430, -971956092, -114159186, -264299872, -349698126, -500888388, -1787927066, -1671205144, -2022411270, -1904641804, -1319482914, -1202240816, -1556062270, -1437772596, -321194175, -438830001, -20913827, -137500077, -923870343, -1042034569, -621490843, -738605461, -1531793615, -1379949505, -1230456531, -1079659997, -2138668279, -1987344377, -1835231979, -1684955621, 2081048481, 1963412655, 1846563261, 1729977011, 1480485785, 1362321559, 1243905413, 1126790795, 878845905, 1030690015, 645401037, 796197571, 274084841, 425408743, 38544885, 188821243, -681472870, -563312748, -981755258, -864644728, -212492126, -94852180, -514869570, -398279248, -1626745622, -1778065436, -1928084746, -2078357000, -1153566510, -1305414692, -1457000754, -1607801408, 1202797690, 1320957812, 1437280870, 1554391400, 1669664834, 1787304780, 1906247262, 2022837584, 265905162, 114585348, 499347990, 349075736, 736970802, 585122620, 972512814, 821712160, -1699282452, -1816524062, -2001922064, -2120213250, -1098699308, -1215420710, -1399243832, -1517014842, -757114468, -606973294, -1060810880, -909622130, -152341084, -1671510, -453942344, -302225226, 174567692, 57326082, 410887952, 292596766, 777231668, 660510266, 1011452712, 893681702, 1108339068, 1258480242, 1343618912, 1494807662, 1715193156, 1865862730, 1948373848, 2100090966, -1593017801, -1476300487, -1290376149, -1172609243, -2059905521, -1942659839, -1759363053, -1641067747, -379313593, -529979063, -75615141, -227328171, -850391425, -1000536719, -548792221, -699985043, 836553431, 953270745, 600235211, 718002117, 367585007, 484830689, 133361907, 251657213, 2041877159, 1891211689, 1806599355, 1654886325, 1568718495, 1418573201, 1335535747, 1184342925 }; private readonly int[] sm_U4 = new int[] { 0, 151849742, 303699484, 454499602, 607398968, 758720310, 908999204, 1059270954, 1214797936, 1097159550, 1517440620, 1400849762, 1817998408, 1699839814, 2118541908, 2001430874, -1865371424, -1713521682, -2100648196, -1949848078, -1260086056, -1108764714, -1493267772, -1342996022, -658970480, -776608866, -895287668, -1011878526, -57883480, -176042074, -292105548, -409216582, 1002142683, 850817237, 698445255, 548169417, 529487843, 377642221, 227885567, 77089521, 1943217067, 2061379749, 1640576439, 1757691577, 1474760595, 1592394909, 1174215055, 1290801793, -1418998981, -1570324427, -1183720153, -1333995991, -1889540349, -2041385971, -1656360673, -1807156719, -486304949, -368142267, -249985705, -132870567, -952647821, -835013507, -718427793, -601841055, 1986918061, 2137062819, 1685577905, 1836772287, 1381620373, 1532285339, 1078185097, 1229899655, 1040559837, 923313619, 740276417, 621982671, 439452389, 322734571, 137073913, 19308535, -423803315, -273658557, -190361519, -39167137, -1031181707, -880516741, -795640727, -643926169, -1361764803, -1479011021, -1127282655, -1245576401, -1964953083, -2081670901, -1728371687, -1846137065, 1305906550, 1155237496, 1607244650, 1455525988, 1776460110, 1626319424, 2079897426, 1928707164, 96392454, 213114376, 396673818, 514443284, 562755902, 679998000, 865136418, 983426092, -586793578, -737462632, -820237430, -971956092, -114159186, -264299872, -349698126, -500888388, -1787927066, -1671205144, -2022411270, -1904641804, -1319482914, -1202240816, -1556062270, -1437772596, -321194175, -438830001, -20913827, -137500077, -923870343, -1042034569, -621490843, -738605461, -1531793615, -1379949505, -1230456531, -1079659997, -2138668279, -1987344377, -1835231979, -1684955621, 2081048481, 1963412655, 1846563261, 1729977011, 1480485785, 1362321559, 1243905413, 1126790795, 878845905, 1030690015, 645401037, 796197571, 274084841, 425408743, 38544885, 188821243, -681472870, -563312748, -981755258, -864644728, -212492126, -94852180, -514869570, -398279248, -1626745622, -1778065436, -1928084746, -2078357000, -1153566510, -1305414692, -1457000754, -1607801408, 1202797690, 1320957812, 1437280870, 1554391400, 1669664834, 1787304780, 1906247262, 2022837584, 265905162, 114585348, 499347990, 349075736, 736970802, 585122620, 972512814, 821712160, -1699282452, -1816524062, -2001922064, -2120213250, -1098699308, -1215420710, -1399243832, -1517014842, -757114468, -606973294, -1060810880, -909622130, -152341084, -1671510, -453942344, -302225226, 174567692, 57326082, 410887952, 292596766, 777231668, 660510266, 1011452712, 893681702, 1108339068, 1258480242, 1343618912, 1494807662, 1715193156, 1865862730, 1948373848, 2100090966, -1593017801, -1476300487, -1290376149, -1172609243, -2059905521, -1942659839, -1759363053, -1641067747, -379313593, -529979063, -75615141, -227328171, -850391425, -1000536719, -548792221, -699985043, 836553431, 953270745, 600235211, 718002117, 367585007, 484830689, 133361907, 251657213, 2041877159, 1891211689, 1806599355, 1654886325, 1568718495, 1418573201, 1335535747, 1184342925 };
private readonly byte[] sm_rcon = new byte[] { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91 }; private readonly byte[] sm_rcon = new byte[] { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91 };
readonly int[] t = new int[8]; readonly int[] tk = new int[MAX_KC];
readonly int[] tk = new int[8];
private bool bKeyInit;
int iROUNDS;
public HLEncoder(string pwd) public HLEncoder(string pwd)
{ {
@ -108,37 +105,37 @@ namespace ScreenLogicConnect
switch (pass.Length) switch (pass.Length)
{ {
case 16: case 16:
this.iROUNDS = 10; iROUNDS = 10;
break; break;
case 24: case 24:
this.iROUNDS = 12; iROUNDS = 12;
break; break;
default: default:
this.iROUNDS = MAX_ROUNDS; iROUNDS = MAX_ROUNDS;
break; break;
} }
for (i = 0; i <= this.iROUNDS; i++) for (i = 0; i <= iROUNDS; i++)
{ {
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
{ {
this.Ke[i, j] = 0; Ke[i, j] = 0;
this.Kd[i, j] = 0; Kd[i, j] = 0;
} }
} }
int ROUND_KEY_COUNT = (this.iROUNDS + 1) * 4; int ROUND_KEY_COUNT = (iROUNDS + 1) * 4;
int KC = pass.Length / 4; int KC = pass.Length / 4;
int j2 = 0; int j2 = 0;
for (i = 0; i < KC; i++) for (i = 0; i < KC; i++)
{ {
j = j2 + 1; j = j2 + 1;
this.tk[i] = pass[j2] << 24; tk[i] = pass[j2] << 24;
iArr = this.tk; iArr = tk;
j2 = j + 1; j2 = j + 1;
iArr[i] = iArr[i] | (pass[j] << 16); iArr[i] = iArr[i] | (pass[j] << 16);
iArr = this.tk; iArr = tk;
j = j2 + 1; j = j2 + 1;
iArr[i] = iArr[i] | (pass[j2] << 8); iArr[i] = iArr[i] | (pass[j2] << 8);
iArr = this.tk; iArr = tk;
j2 = j + 1; j2 = j + 1;
iArr[i] = iArr[i] | pass[j]; iArr[i] = iArr[i] | pass[j];
} }
@ -146,18 +143,18 @@ namespace ScreenLogicConnect
i = 0; i = 0;
while (i < KC && t < ROUND_KEY_COUNT) while (i < KC && t < ROUND_KEY_COUNT)
{ {
this.Ke[t / 4, t % 4] = this.tk[i]; Ke[t / 4, t % 4] = tk[i];
this.Kd[this.iROUNDS - (t / 4), t % 4] = this.tk[i]; Kd[iROUNDS - (t / 4), t % 4] = tk[i];
i++; i++;
t++; t++;
} }
int rconpointer = 0; int rconpointer = 0;
while (t < ROUND_KEY_COUNT) while (t < ROUND_KEY_COUNT)
{ {
tt = this.tk[KC - 1]; tt = tk[KC - 1];
iArr = this.tk; iArr = tk;
int rconpointer2 = rconpointer + 1; int rconpointer2 = rconpointer + 1;
iArr[0] = iArr[0] ^ ((((((this.sm_S[(tt >> 16) & 255] & 255) << 24) ^ ((this.sm_S[(tt >> 8) & 255] & 255) << 16)) ^ ((this.sm_S[tt & 255] & 255) << 8)) ^ (this.sm_S[(tt >> 24) & 255] & 255)) ^ ((this.sm_rcon[rconpointer] & 255) << 24)); iArr[0] = iArr[0] ^ ((((((sm_S[(tt >> 16) & 255] & 255) << 24) ^ ((sm_S[(tt >> 8) & 255] & 255) << 16)) ^ ((sm_S[tt & 255] & 255) << 8)) ^ (sm_S[(tt >> 24) & 255] & 255)) ^ ((sm_rcon[rconpointer] & 255) << 24));
int i2; int i2;
if (KC != MAX_KC) if (KC != MAX_KC)
{ {
@ -165,10 +162,10 @@ namespace ScreenLogicConnect
i2 = 1; i2 = 1;
while (i2 < KC) while (i2 < KC)
{ {
iArr = this.tk; iArr = tk;
i = i2 + 1; i = i2 + 1;
j = j2 + 1; j = j2 + 1;
iArr[i2] = iArr[i2] ^ this.tk[j2]; iArr[i2] = iArr[i2] ^ tk[j2];
j2 = j; j2 = j;
i2 = i; i2 = i;
} }
@ -179,26 +176,26 @@ namespace ScreenLogicConnect
j = 0; j = 0;
while (i < KC / 2) while (i < KC / 2)
{ {
iArr = this.tk; iArr = tk;
i2 = i + 1; i2 = i + 1;
j2 = j + 1; j2 = j + 1;
iArr[i] = iArr[i] ^ this.tk[j]; iArr[i] = iArr[i] ^ tk[j];
j = j2; j = j2;
i = i2; i = i2;
} }
tt = this.tk[(KC / 2) - 1]; tt = tk[(KC / 2) - 1];
iArr = this.tk; iArr = tk;
int i3 = KC / 2; int i3 = KC / 2;
iArr[i3] = iArr[i3] ^ ((((this.sm_S[tt & 255] & 255) ^ ((this.sm_S[(tt >> 8) & 255] & 255) << 8)) ^ ((this.sm_S[(tt >> 16) & 255] & 255) << 16)) ^ ((this.sm_S[(tt >> 24) & 255] & 255) << 24)); iArr[i3] = iArr[i3] ^ ((((sm_S[tt & 255] & 255) ^ ((sm_S[(tt >> 8) & 255] & 255) << 8)) ^ ((sm_S[(tt >> 16) & 255] & 255) << 16)) ^ ((sm_S[(tt >> 24) & 255] & 255) << 24));
j = KC / 2; j = KC / 2;
i2 = j + 1; i2 = j + 1;
j2 = j; j2 = j;
while (i2 < KC) while (i2 < KC)
{ {
iArr = this.tk; iArr = tk;
i = i2 + 1; i = i2 + 1;
j = j2 + 1; j = j2 + 1;
iArr[i2] = iArr[i2] ^ this.tk[j2]; iArr[i2] = iArr[i2] ^ tk[j2];
i2 = i; i2 = i;
j2 = j; j2 = j;
} }
@ -206,112 +203,61 @@ namespace ScreenLogicConnect
j = 0; j = 0;
while (j < KC && t < ROUND_KEY_COUNT) while (j < KC && t < ROUND_KEY_COUNT)
{ {
this.Ke[t / 4, t % 4] = this.tk[j]; Ke[t / 4, t % 4] = tk[j];
this.Kd[this.iROUNDS - (t / 4), t % 4] = this.tk[j]; Kd[iROUNDS - (t / 4), t % 4] = tk[j];
j++; j++;
t++; t++;
} }
rconpointer = rconpointer2; rconpointer = rconpointer2;
} }
for (int r = 1; r < this.iROUNDS; r++) for (int r = 1; r < iROUNDS; r++)
{ {
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
{ {
tt = this.Kd[r, j]; tt = Kd[r, j];
this.Kd[r, j] = ((this.sm_U1[(tt >> 24) & 255] ^ this.sm_U2[(tt >> 16) & 255]) ^ this.sm_U3[(tt >> 8) & 255]) ^ this.sm_U4[tt & 255]; Kd[r, j] = ((sm_U1[(tt >> 24) & 255] ^ sm_U2[(tt >> 16) & 255]) ^ sm_U3[(tt >> 8) & 255]) ^ sm_U4[tt & 255];
} }
} }
this.bKeyInit = true; bKeyInit = true;
} }
} }
private byte[] EncryptBlock(byte[] block) private byte[] EncryptBlock(byte[] block)
{ {
if (!this.bKeyInit) if (!bKeyInit)
{ {
return null; return null;
} }
int i10 = 0 + 1;
int i8 = block[0]; var a = (block[0] << 24 | block[1] << 16 | block[2] << 8 | block[3]) ^ Ke[0, 0];
int i9 = i10 + 1; var b = (block[4] << 24 | block[5] << 16 | block[6] << 8 | block[7]) ^ Ke[0, 1];
i10 = block[i10]; var c = (block[8] << 24 | block[9] << 16 | block[10] << 8 | block[11]) ^ Ke[0, 2];
int i11 = i9 + 1; var d = (block[12] << 24 | block[13] << 16 | block[14] << 8 | block[15]) ^ Ke[0, 3];
int i12 = block[i9]; for (int round = 1; round < iROUNDS; round++)
i9 = i11 + 1;
i11 = (i8 << 24 | i10 << 16 | i12 << 8 | (byte)block[i11]) ^ this.Ke[0, 0];
i12 = i9 + 1;
i8 = block[i9];
i10 = i12 + 1;
i9 = block[i12];
i12 = i10 + 1;
int i13 = block[i10];
i10 = i12 + 1;
i9 = (i8 << 24 | i9 << 16 | i13 << 8 | (byte)block[i12]) ^ this.Ke[0, 1];
i12 = i10 + 1;
i8 = block[i10];
i10 = i12 + 1;
i12 = block[i12];
i13 = i10 + 1;
int i14 = block[i10];
i10 = i13 + 1;
i8 = (i8 << 24 | i12 << 16 | i14 << 8 | (byte)block[i13]) ^ this.Ke[0, 2];
i13 = i10 + 1;
i10 = block[i10];
i12 = i13 + 1;
i13 = block[i13];
i14 = i12 + 1;
i12 = (i10 << 24 | i13 << 16 | block[i12] << 8 | (byte)block[i14]) ^ this.Ke[0, 3];
i10 = 1;
while (i10 < this.iROUNDS)
{ {
int i24 = this.sm_T1[(i11 >> 24 & 0xFF)]; var a1 = sm_T1[(a >> 24 & 0xFF)] ^ sm_T2[(b >> 16 & 0xFF)] ^ sm_T3[(c >> 8 & 0xFF)] ^ sm_T4[(d & 0xFF)] ^ Ke[round, 0];
int i25 = this.sm_T2[(i9 >> 16 & 0xFF)]; var b1 = sm_T1[(b >> 24 & 0xFF)] ^ sm_T2[(c >> 16 & 0xFF)] ^ sm_T3[(d >> 8 & 0xFF)] ^ sm_T4[(a & 0xFF)] ^ Ke[round, 1];
int i26 = this.sm_T3[(i8 >> 8 & 0xFF)]; var c1 = sm_T1[(c >> 24 & 0xFF)] ^ sm_T2[(d >> 16 & 0xFF)] ^ sm_T3[(a >> 8 & 0xFF)] ^ sm_T4[(b & 0xFF)] ^ Ke[round, 2];
int i27 = this.sm_T4[(i12 & 0xFF)]; var d1 = sm_T1[(d >> 24 & 0xFF)] ^ sm_T2[(a >> 16 & 0xFF)] ^ sm_T3[(b >> 8 & 0xFF)] ^ sm_T4[(c & 0xFF)] ^ Ke[round, 3];
int i28 = this.Ke[i10, 0];
int i18 = this.sm_T1[(i9 >> 24 & 0xFF)]; a = a1;
int i19 = this.sm_T2[(i8 >> 16 & 0xFF)]; b = b1;
int i20 = this.sm_T3[(i12 >> 8 & 0xFF)]; c = c1;
int i21 = this.sm_T4[(i11 & 0xFF)]; d = d1;
int i22 = this.Ke[i10, 1];
i13 = this.sm_T1[(i8 >> 24 & 0xFF)];
i14 = this.sm_T2[(i12 >> 16 & 0xFF)];
int i15 = this.sm_T3[(i11 >> 8 & 0xFF)];
int i16 = this.sm_T4[(i9 & 0xFF)];
int i17 = this.Ke[i10, 2];
i12 = this.sm_T1[(i12 >> 24 & 0xFF)];
int i23 = this.sm_T2[(i11 >> 16 & 0xFF)];
int i29 = this.sm_T3[(i9 >> 8 & 0xFF)];
int i30 = this.sm_T4[(i8 & 0xFF)];
int i31 = this.Ke[i10, 3];
i11 = i24 ^ i25 ^ i26 ^ i27 ^ i28;
i9 = i18 ^ i19 ^ i20 ^ i21 ^ i22;
i8 = i13 ^ i14 ^ i15 ^ i16 ^ i17;
i12 = i12 ^ i23 ^ i29 ^ i30 ^ i31;
i10 += 1;
} }
i10 = this.Ke[this.iROUNDS, 0];
byte i = (byte)(this.sm_S[(i11 >> 24 & 0xFF)] ^ i10 >> 24); return new byte[]
byte j = (byte)(this.sm_S[(i9 >> 16 & 0xFF)] ^ i10 >> 16); {
byte k = (byte)(this.sm_S[(i8 >> 8 & 0xFF)] ^ i10 >> 8); (byte)(sm_S[(a >> 24 & 0xFF)] ^ Ke[iROUNDS, 0] >> 24), (byte)(sm_S[(b >> 16 & 0xFF)] ^ Ke[iROUNDS, 0] >> 16), (byte)(sm_S[(c >> 8 & 0xFF)] ^ Ke[iROUNDS, 0] >> 8), (byte)(sm_S[(d & 0xFF)] ^ Ke[iROUNDS, 0]),
byte m = (byte)(this.sm_S[(i12 & 0xFF)] ^ i10); (byte)(sm_S[(b >> 24 & 0xFF)] ^ Ke[iROUNDS, 1] >> 24), (byte)(sm_S[(c >> 16 & 0xFF)] ^ Ke[iROUNDS, 1] >> 16), (byte)(sm_S[(d >> 8 & 0xFF)] ^ Ke[iROUNDS, 1] >> 8), (byte)(sm_S[(a & 0xFF)] ^ Ke[iROUNDS, 1]),
i10 = this.Ke[this.iROUNDS, 1]; (byte)(sm_S[(c >> 24 & 0xFF)] ^ Ke[iROUNDS, 2] >> 24), (byte)(sm_S[(d >> 16 & 0xFF)] ^ Ke[iROUNDS, 2] >> 16), (byte)(sm_S[(a >> 8 & 0xFF)] ^ Ke[iROUNDS, 2] >> 8), (byte)(sm_S[(b & 0xFF)] ^ Ke[iROUNDS, 2]),
byte n = (byte)(this.sm_S[(i9 >> 24 & 0xFF)] ^ i10 >> 24); (byte)(sm_S[(d >> 24 & 0xFF)] ^ Ke[iROUNDS, 3] >> 24), (byte)(sm_S[(a >> 16 & 0xFF)] ^ Ke[iROUNDS, 3] >> 16), (byte)(sm_S[(b >> 8 & 0xFF)] ^ Ke[iROUNDS, 3] >> 8), (byte)(sm_S[(c & 0xFF)] ^ Ke[iROUNDS, 3])
byte i1 = (byte)(this.sm_S[(i8 >> 16 & 0xFF)] ^ i10 >> 16); };
byte i2 = (byte)(this.sm_S[(i12 >> 8 & 0xFF)] ^ i10 >> 8);
byte i3 = (byte)(this.sm_S[(i11 & 0xFF)] ^ i10);
i10 = this.Ke[this.iROUNDS, 2];
byte i4 = (byte)(this.sm_S[(i8 >> 24 & 0xFF)] ^ i10 >> 24);
byte i5 = (byte)(this.sm_S[(i12 >> 16 & 0xFF)] ^ i10 >> 16);
byte i6 = (byte)(this.sm_S[(i11 >> 8 & 0xFF)] ^ i10 >> 8);
byte i7 = (byte)(this.sm_S[(i9 & 0xFF)] ^ i10);
i10 = this.Ke[this.iROUNDS, 3];
return new byte[] { i, j, k, m, n, i1, i2, i3, i4, i5, i6, i7, (byte)(this.sm_S[(i12 >> 24 & 0xFF)] ^ i10 >> 24), (byte)(this.sm_S[(i11 >> 16 & 0xFF)] ^ i10 >> 16), (byte)(this.sm_S[(i9 >> 8 & 0xFF)] ^ i10 >> 8), (byte)(this.sm_S[(i8 & 0xFF)] ^ i10) };
} }
byte[] Encrypt(string sString) byte[] Encrypt(string sString)
{ {
if (this.bKeyInit) if (bKeyInit)
{ {
return EncryptData(MakeBlock(sString, 0)); return EncryptData(MakeBlock(sString, 0));
} }
@ -320,7 +266,7 @@ namespace ScreenLogicConnect
byte[] Encrypt(byte[] source) byte[] Encrypt(byte[] source)
{ {
if (this.bKeyInit) if (bKeyInit)
{ {
return EncryptData(MakeBlock(source, 0)); return EncryptData(MakeBlock(source, 0));
} }