encode_info.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. import execjs,json
  2. js_str = '''
  3. function CurentTime() {
  4. var now = new Date();
  5. var year = now.getFullYear();
  6. //年
  7. var month = now.getMonth() + 1;
  8. //月
  9. var day = now.getDate();
  10. //日
  11. var hh = now.getHours();
  12. //时
  13. var mm = now.getMinutes();
  14. //分
  15. var ss = now.getSeconds();
  16. if (ss > 30) {
  17. if (mm == 59) {
  18. hh = hh + 1;
  19. mm = 0;
  20. } else {
  21. mm = mm + 1;
  22. }
  23. }
  24. var clock = year + "-";
  25. if (month < 10)
  26. clock += "0";
  27. clock += month + "-";
  28. if (day < 10)
  29. clock += "0";
  30. clock += day + " ";
  31. if (hh < 10)
  32. clock += "0";
  33. clock += hh;
  34. //clock += hh + ":";
  35. //if (mm < 10) clock += '0';
  36. //clock += mm;
  37. return (clock);
  38. };
  39. function getKeyBytes(key){
  40. var keyBytes = new Array();
  41. var leng = key.length;
  42. var iterator = parseInt(leng/4);
  43. var remainder = leng%4;
  44. var i = 0;
  45. for(i = 0;i < iterator; i ++){
  46. keyBytes[i] = strToBt(key.substring(i*4+0,i*4+4));
  47. }
  48. if(remainder > 0){
  49. keyBytes[i] = strToBt(key.substring(i*4+0,leng));
  50. }
  51. return keyBytes;
  52. };
  53. function strToBt(str){
  54. var leng = str.length;
  55. var bt = new Array(64);
  56. if(leng < 4){
  57. var i=0,j=0,p=0,q=0;
  58. for(i = 0;i<leng;i++){
  59. var k = str.charCodeAt(i);
  60. for(j=0;j<16;j++){
  61. var pow=1,m=0;
  62. for(m=15;m>j;m--){
  63. pow *= 2;
  64. }
  65. bt[16*i+j]=parseInt(k/pow)%2;
  66. }
  67. }
  68. for(p = leng;p<4;p++){
  69. var k = 0;
  70. for(q=0;q<16;q++){
  71. var pow=1,m=0;
  72. for(m=15;m>q;m--){
  73. pow *= 2;
  74. }
  75. bt[16*p+q]=parseInt(k/pow)%2;
  76. }
  77. }
  78. }else{
  79. for(i = 0;i<4;i++){
  80. var k = str.charCodeAt(i);
  81. for(j=0;j<16;j++){
  82. var pow=1;
  83. for(m=15;m>j;m--){
  84. pow *= 2;
  85. }
  86. bt[16*i+j]=parseInt(k/pow)%2;
  87. }
  88. }
  89. }
  90. return bt;
  91. };
  92. function enc(dataByte,keyByte){
  93. var keys = generateKeys(keyByte);
  94. var ipByte = initPermute(dataByte);
  95. var ipLeft = new Array(32);
  96. var ipRight = new Array(32);
  97. var tempLeft = new Array(32);
  98. var i = 0,j = 0,k = 0,m = 0, n = 0;
  99. for(k = 0;k < 32;k ++){
  100. ipLeft[k] = ipByte[k];
  101. ipRight[k] = ipByte[32+k];
  102. }
  103. for(i = 0;i < 16;i ++){
  104. for(j = 0;j < 32;j ++){
  105. tempLeft[j] = ipLeft[j];
  106. ipLeft[j] = ipRight[j];
  107. }
  108. var key = new Array(48);
  109. for(m = 0;m < 48;m ++){
  110. key[m] = keys[i][m];
  111. }
  112. var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);
  113. for(n = 0;n < 32;n ++){
  114. ipRight[n] = tempRight[n];
  115. }
  116. }
  117. var finalData =new Array(64);
  118. for(i = 0;i < 32;i ++){
  119. finalData[i] = ipRight[i];
  120. finalData[32+i] = ipLeft[i];
  121. }
  122. return finallyPermute(finalData)}
  123. ;
  124. function generateKeys(keyByte){
  125. var key = new Array(56);
  126. var keys = new Array();
  127. keys[ 0] = new Array();
  128. keys[ 1] = new Array();
  129. keys[ 2] = new Array();
  130. keys[ 3] = new Array();
  131. keys[ 4] = new Array();
  132. keys[ 5] = new Array();
  133. keys[ 6] = new Array();
  134. keys[ 7] = new Array();
  135. keys[ 8] = new Array();
  136. keys[ 9] = new Array();
  137. keys[10] = new Array();
  138. keys[11] = new Array();
  139. keys[12] = new Array();
  140. keys[13] = new Array();
  141. keys[14] = new Array();
  142. keys[15] = new Array();
  143. var loop = [1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1];
  144. for(i=0;i<7;i++){
  145. for(j=0,k=7;j<8;j++,k--){
  146. key[i*8+j]=keyByte[8*k+i];
  147. }
  148. }
  149. var i = 0;
  150. for(i = 0;i < 16;i ++){
  151. var tempLeft=0;
  152. var tempRight=0;
  153. for(j = 0; j < loop[i];j ++){
  154. tempLeft = key[0];
  155. tempRight = key[28];
  156. for(k = 0;k < 27 ;k ++){
  157. key[k] = key[k+1];
  158. key[28+k] = key[29+k];
  159. }
  160. key[27]=tempLeft;
  161. key[55]=tempRight;
  162. }
  163. var tempKey = new Array(48);
  164. tempKey[ 0] = key[13];
  165. tempKey[ 1] = key[16];
  166. tempKey[ 2] = key[10];
  167. tempKey[ 3] = key[23];
  168. tempKey[ 4] = key[ 0];
  169. tempKey[ 5] = key[ 4];
  170. tempKey[ 6] = key[ 2];
  171. tempKey[ 7] = key[27];
  172. tempKey[ 8] = key[14];
  173. tempKey[ 9] = key[ 5];
  174. tempKey[10] = key[20];
  175. tempKey[11] = key[ 9];
  176. tempKey[12] = key[22];
  177. tempKey[13] = key[18];
  178. tempKey[14] = key[11];
  179. tempKey[15] = key[ 3];
  180. tempKey[16] = key[25];
  181. tempKey[17] = key[ 7];
  182. tempKey[18] = key[15];
  183. tempKey[19] = key[ 6];
  184. tempKey[20] = key[26];
  185. tempKey[21] = key[19];
  186. tempKey[22] = key[12];
  187. tempKey[23] = key[ 1];
  188. tempKey[24] = key[40];
  189. tempKey[25] = key[51];
  190. tempKey[26] = key[30];
  191. tempKey[27] = key[36];
  192. tempKey[28] = key[46];
  193. tempKey[29] = key[54];
  194. tempKey[30] = key[29];
  195. tempKey[31] = key[39];
  196. tempKey[32] = key[50];
  197. tempKey[33] = key[44];
  198. tempKey[34] = key[32];
  199. tempKey[35] = key[47];
  200. tempKey[36] = key[43];
  201. tempKey[37] = key[48];
  202. tempKey[38] = key[38];
  203. tempKey[39] = key[55];
  204. tempKey[40] = key[33];
  205. tempKey[41] = key[52];
  206. tempKey[42] = key[45];
  207. tempKey[43] = key[41];
  208. tempKey[44] = key[49];
  209. tempKey[45] = key[35];
  210. tempKey[46] = key[28];
  211. tempKey[47] = key[31];
  212. switch(i){
  213. case 0: for(m=0;m < 48 ;m++){ keys[ 0][m] = tempKey[m]; } break;
  214. case 1: for(m=0;m < 48 ;m++){ keys[ 1][m] = tempKey[m]; } break;
  215. case 2: for(m=0;m < 48 ;m++){ keys[ 2][m] = tempKey[m]; } break;
  216. case 3: for(m=0;m < 48 ;m++){ keys[ 3][m] = tempKey[m]; } break;
  217. case 4: for(m=0;m < 48 ;m++){ keys[ 4][m] = tempKey[m]; } break;
  218. case 5: for(m=0;m < 48 ;m++){ keys[ 5][m] = tempKey[m]; } break;
  219. case 6: for(m=0;m < 48 ;m++){ keys[ 6][m] = tempKey[m]; } break;
  220. case 7: for(m=0;m < 48 ;m++){ keys[ 7][m] = tempKey[m]; } break;
  221. case 8: for(m=0;m < 48 ;m++){ keys[ 8][m] = tempKey[m]; } break;
  222. case 9: for(m=0;m < 48 ;m++){ keys[ 9][m] = tempKey[m]; } break;
  223. case 10: for(m=0;m < 48 ;m++){ keys[10][m] = tempKey[m]; } break;
  224. case 11: for(m=0;m < 48 ;m++){ keys[11][m] = tempKey[m]; } break;
  225. case 12: for(m=0;m < 48 ;m++){ keys[12][m] = tempKey[m]; } break;
  226. case 13: for(m=0;m < 48 ;m++){ keys[13][m] = tempKey[m]; } break;
  227. case 14: for(m=0;m < 48 ;m++){ keys[14][m] = tempKey[m]; } break;
  228. case 15: for(m=0;m < 48 ;m++){ keys[15][m] = tempKey[m]; } break;
  229. }
  230. }
  231. return keys;
  232. };
  233. function initPermute(originalData){
  234. var ipByte = new Array(64);
  235. for (i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) {
  236. for (j = 7, k = 0; j >= 0; j--, k++) {
  237. ipByte[i * 8 + k] = originalData[j * 8 + m];
  238. ipByte[i * 8 + k + 32] = originalData[j * 8 + n];
  239. }
  240. }
  241. return ipByte;
  242. };
  243. function xor(byteOne,byteTwo){
  244. var xorByte = new Array(byteOne.length);
  245. for(i = 0;i < byteOne.length; i ++){
  246. xorByte[i] = byteOne[i] ^ byteTwo[i];
  247. }
  248. return xorByte;
  249. };
  250. function pPermute(sBoxByte){
  251. var pBoxPermute = new Array(32);
  252. pBoxPermute[ 0] = sBoxByte[15];
  253. pBoxPermute[ 1] = sBoxByte[ 6];
  254. pBoxPermute[ 2] = sBoxByte[19];
  255. pBoxPermute[ 3] = sBoxByte[20];
  256. pBoxPermute[ 4] = sBoxByte[28];
  257. pBoxPermute[ 5] = sBoxByte[11];
  258. pBoxPermute[ 6] = sBoxByte[27];
  259. pBoxPermute[ 7] = sBoxByte[16];
  260. pBoxPermute[ 8] = sBoxByte[ 0];
  261. pBoxPermute[ 9] = sBoxByte[14];
  262. pBoxPermute[10] = sBoxByte[22];
  263. pBoxPermute[11] = sBoxByte[25];
  264. pBoxPermute[12] = sBoxByte[ 4];
  265. pBoxPermute[13] = sBoxByte[17];
  266. pBoxPermute[14] = sBoxByte[30];
  267. pBoxPermute[15] = sBoxByte[ 9];
  268. pBoxPermute[16] = sBoxByte[ 1];
  269. pBoxPermute[17] = sBoxByte[ 7];
  270. pBoxPermute[18] = sBoxByte[23];
  271. pBoxPermute[19] = sBoxByte[13];
  272. pBoxPermute[20] = sBoxByte[31];
  273. pBoxPermute[21] = sBoxByte[26];
  274. pBoxPermute[22] = sBoxByte[ 2];
  275. pBoxPermute[23] = sBoxByte[ 8];
  276. pBoxPermute[24] = sBoxByte[18];
  277. pBoxPermute[25] = sBoxByte[12];
  278. pBoxPermute[26] = sBoxByte[29];
  279. pBoxPermute[27] = sBoxByte[ 5];
  280. pBoxPermute[28] = sBoxByte[21];
  281. pBoxPermute[29] = sBoxByte[10];
  282. pBoxPermute[30] = sBoxByte[ 3];
  283. pBoxPermute[31] = sBoxByte[24];
  284. return pBoxPermute;
  285. };
  286. function sBoxPermute(expandByte){
  287. var sBoxByte = new Array(32);
  288. var binary = "";
  289. var s1 = [
  290. [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],
  291. [0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],
  292. [4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],
  293. [15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 ]];
  294. /* Table - s2 */
  295. var s2 = [
  296. [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],
  297. [3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],
  298. [0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],
  299. [13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 ]];
  300. /* Table - s3 */
  301. var s3= [
  302. [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],
  303. [13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],
  304. [13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],
  305. [1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 ]];
  306. /* Table - s4 */
  307. var s4 = [
  308. [7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],
  309. [13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],
  310. [10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],
  311. [3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 ]];
  312. /* Table - s5 */
  313. var s5 = [
  314. [2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],
  315. [14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],
  316. [4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],
  317. [11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 ]];
  318. /* Table - s6 */
  319. var s6 = [
  320. [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],
  321. [10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],
  322. [9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],
  323. [4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 ]];
  324. /* Table - s7 */
  325. var s7 = [
  326. [4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],
  327. [13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],
  328. [1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],
  329. [6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]];
  330. /* Table - s8 */
  331. var s8 = [
  332. [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
  333. [1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
  334. [7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
  335. [2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]];
  336. for(m=0;m<8;m++){
  337. var i=0,j=0;
  338. i = expandByte[m*6+0]*2+expandByte[m*6+5];
  339. j = expandByte[m * 6 + 1] * 2 * 2 * 2
  340. + expandByte[m * 6 + 2] * 2* 2
  341. + expandByte[m * 6 + 3] * 2
  342. + expandByte[m * 6 + 4];
  343. switch (m) {
  344. case 0 :
  345. binary = getBoxBinary(s1[i][j]);
  346. break;
  347. case 1 :
  348. binary = getBoxBinary(s2[i][j]);
  349. break;
  350. case 2 :
  351. binary = getBoxBinary(s3[i][j]);
  352. break;
  353. case 3 :
  354. binary = getBoxBinary(s4[i][j]);
  355. break;
  356. case 4 :
  357. binary = getBoxBinary(s5[i][j]);
  358. break;
  359. case 5 :
  360. binary = getBoxBinary(s6[i][j]);
  361. break;
  362. case 6 :
  363. binary = getBoxBinary(s7[i][j]);
  364. break;
  365. case 7 :
  366. binary = getBoxBinary(s8[i][j]);
  367. break;
  368. }
  369. sBoxByte[m*4+0] = parseInt(binary.substring(0,1));
  370. sBoxByte[m*4+1] = parseInt(binary.substring(1,2));
  371. sBoxByte[m*4+2] = parseInt(binary.substring(2,3));
  372. sBoxByte[m*4+3] = parseInt(binary.substring(3,4));
  373. }
  374. return sBoxByte;
  375. };
  376. function expandPermute(rightData){
  377. var epByte = new Array(48);
  378. for (i = 0; i < 8; i++) {
  379. if (i == 0) {
  380. epByte[i * 6 + 0] = rightData[31];
  381. } else {
  382. epByte[i * 6 + 0] = rightData[i * 4 - 1];
  383. }
  384. epByte[i * 6 + 1] = rightData[i * 4 + 0];
  385. epByte[i * 6 + 2] = rightData[i * 4 + 1];
  386. epByte[i * 6 + 3] = rightData[i * 4 + 2];
  387. epByte[i * 6 + 4] = rightData[i * 4 + 3];
  388. if (i == 7) {
  389. epByte[i * 6 + 5] = rightData[0];
  390. } else {
  391. epByte[i * 6 + 5] = rightData[i * 4 + 4];
  392. }
  393. }
  394. return epByte;
  395. };
  396. function getBoxBinary(i) {
  397. var binary = "";
  398. switch (i) {
  399. case 0 :binary = "0000";break;
  400. case 1 :binary = "0001";break;
  401. case 2 :binary = "0010";break;
  402. case 3 :binary = "0011";break;
  403. case 4 :binary = "0100";break;
  404. case 5 :binary = "0101";break;
  405. case 6 :binary = "0110";break;
  406. case 7 :binary = "0111";break;
  407. case 8 :binary = "1000";break;
  408. case 9 :binary = "1001";break;
  409. case 10 :binary = "1010";break;
  410. case 11 :binary = "1011";break;
  411. case 12 :binary = "1100";break;
  412. case 13 :binary = "1101";break;
  413. case 14 :binary = "1110";break;
  414. case 15 :binary = "1111";break;
  415. }
  416. return binary;
  417. };
  418. function finallyPermute(endByte){
  419. var fpByte = new Array(64);
  420. fpByte[ 0] = endByte[39];
  421. fpByte[ 1] = endByte[ 7];
  422. fpByte[ 2] = endByte[47];
  423. fpByte[ 3] = endByte[15];
  424. fpByte[ 4] = endByte[55];
  425. fpByte[ 5] = endByte[23];
  426. fpByte[ 6] = endByte[63];
  427. fpByte[ 7] = endByte[31];
  428. fpByte[ 8] = endByte[38];
  429. fpByte[ 9] = endByte[ 6];
  430. fpByte[10] = endByte[46];
  431. fpByte[11] = endByte[14];
  432. fpByte[12] = endByte[54];
  433. fpByte[13] = endByte[22];
  434. fpByte[14] = endByte[62];
  435. fpByte[15] = endByte[30];
  436. fpByte[16] = endByte[37];
  437. fpByte[17] = endByte[ 5];
  438. fpByte[18] = endByte[45];
  439. fpByte[19] = endByte[13];
  440. fpByte[20] = endByte[53];
  441. fpByte[21] = endByte[21];
  442. fpByte[22] = endByte[61];
  443. fpByte[23] = endByte[29];
  444. fpByte[24] = endByte[36];
  445. fpByte[25] = endByte[ 4];
  446. fpByte[26] = endByte[44];
  447. fpByte[27] = endByte[12];
  448. fpByte[28] = endByte[52];
  449. fpByte[29] = endByte[20];
  450. fpByte[30] = endByte[60];
  451. fpByte[31] = endByte[28];
  452. fpByte[32] = endByte[35];
  453. fpByte[33] = endByte[ 3];
  454. fpByte[34] = endByte[43];
  455. fpByte[35] = endByte[11];
  456. fpByte[36] = endByte[51];
  457. fpByte[37] = endByte[19];
  458. fpByte[38] = endByte[59];
  459. fpByte[39] = endByte[27];
  460. fpByte[40] = endByte[34];
  461. fpByte[41] = endByte[ 2];
  462. fpByte[42] = endByte[42];
  463. fpByte[43] = endByte[10];
  464. fpByte[44] = endByte[50];
  465. fpByte[45] = endByte[18];
  466. fpByte[46] = endByte[58];
  467. fpByte[47] = endByte[26];
  468. fpByte[48] = endByte[33];
  469. fpByte[49] = endByte[ 1];
  470. fpByte[50] = endByte[41];
  471. fpByte[51] = endByte[ 9];
  472. fpByte[52] = endByte[49];
  473. fpByte[53] = endByte[17];
  474. fpByte[54] = endByte[57];
  475. fpByte[55] = endByte[25];
  476. fpByte[56] = endByte[32];
  477. fpByte[57] = endByte[ 0];
  478. fpByte[58] = endByte[40];
  479. fpByte[59] = endByte[ 8];
  480. fpByte[60] = endByte[48];
  481. fpByte[61] = endByte[16];
  482. fpByte[62] = endByte[56];
  483. fpByte[63] = endByte[24];
  484. return fpByte;
  485. };
  486. function bt64ToHex(byteData){
  487. var hex = "";
  488. for(i = 0;i<16;i++){
  489. var bt = "";
  490. for(j=0;j<4;j++){
  491. bt += byteData[i*4+j];
  492. }
  493. hex+=bt4ToHex(bt);
  494. }
  495. return hex;
  496. };
  497. function bt4ToHex(binary) {
  498. var hex;
  499. switch (binary) {
  500. case "0000" : hex = "0"; break;
  501. case "0001" : hex = "1"; break;
  502. case "0010" : hex = "2"; break;
  503. case "0011" : hex = "3"; break;
  504. case "0100" : hex = "4"; break;
  505. case "0101" : hex = "5"; break;
  506. case "0110" : hex = "6"; break;
  507. case "0111" : hex = "7"; break;
  508. case "1000" : hex = "8"; break;
  509. case "1001" : hex = "9"; break;
  510. case "1010" : hex = "A"; break;
  511. case "1011" : hex = "B"; break;
  512. case "1100" : hex = "C"; break;
  513. case "1101" : hex = "D"; break;
  514. case "1110" : hex = "E"; break;
  515. case "1111" : hex = "F"; break;
  516. }
  517. return hex;
  518. };
  519. function strEnc(data){
  520. var firstKey = CurentTime();
  521. var secondKey = "cebpubservice";
  522. var thirdKey = "iiss";
  523. var leng = data.length;
  524. var encData = "";
  525. var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
  526. if(firstKey != null && firstKey != ""){
  527. firstKeyBt = getKeyBytes(firstKey);
  528. firstLength = firstKeyBt.length;
  529. }
  530. if(secondKey != null && secondKey != ""){
  531. secondKeyBt = getKeyBytes(secondKey);
  532. secondLength = secondKeyBt.length;
  533. }
  534. if(thirdKey != null && thirdKey != ""){
  535. thirdKeyBt = getKeyBytes(thirdKey);
  536. thirdLength = thirdKeyBt.length;
  537. }
  538. if(leng > 0){
  539. if(leng < 4){
  540. var bt = strToBt(data);
  541. var encByte ;
  542. if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
  543. var tempBt;
  544. var x,y,z;
  545. tempBt = bt;
  546. for(x = 0;x < firstLength ;x ++){
  547. tempBt = enc(tempBt,firstKeyBt[x]);
  548. }
  549. for(y = 0;y < secondLength ;y ++){
  550. tempBt = enc(tempBt,secondKeyBt[y]);
  551. }
  552. for(z = 0;z < thirdLength ;z ++){
  553. tempBt = enc(tempBt,thirdKeyBt[z]);
  554. }
  555. encByte = tempBt;
  556. }else{
  557. if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
  558. var tempBt;
  559. var x,y;
  560. tempBt = bt;
  561. for(x = 0;x < firstLength ;x ++){
  562. tempBt = enc(tempBt,firstKeyBt[x]);
  563. }
  564. for(y = 0;y < secondLength ;y ++){
  565. tempBt = enc(tempBt,secondKeyBt[y]);
  566. }
  567. encByte = tempBt;
  568. }else{
  569. if(firstKey != null && firstKey !=""){
  570. var tempBt;
  571. var x = 0;
  572. tempBt = bt;
  573. for(x = 0;x < firstLength ;x ++){
  574. tempBt = enc(tempBt,firstKeyBt[x]);
  575. }
  576. encByte = tempBt;
  577. }
  578. }
  579. }
  580. encData = bt64ToHex(encByte);
  581. }else{
  582. var iterator = parseInt(leng/4);
  583. var remainder = leng%4;
  584. var i=0;
  585. for(i = 0;i < iterator;i++){
  586. var tempData = data.substring(i*4+0,i*4+4);
  587. var tempByte = strToBt(tempData);
  588. var encByte ;
  589. if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
  590. var tempBt;
  591. var x,y,z;
  592. tempBt = tempByte;
  593. for(x = 0;x < firstLength ;x ++){
  594. tempBt = enc(tempBt,firstKeyBt[x]);
  595. }
  596. for(y = 0;y < secondLength ;y ++){
  597. tempBt = enc(tempBt,secondKeyBt[y]);
  598. }
  599. for(z = 0;z < thirdLength ;z ++){
  600. tempBt = enc(tempBt,thirdKeyBt[z]);
  601. }
  602. encByte = tempBt;
  603. }else{
  604. if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
  605. var tempBt;
  606. var x,y;
  607. tempBt = tempByte;
  608. for(x = 0;x < firstLength ;x ++){
  609. tempBt = enc(tempBt,firstKeyBt[x]);
  610. }
  611. for(y = 0;y < secondLength ;y ++){
  612. tempBt = enc(tempBt,secondKeyBt[y]);
  613. }
  614. encByte = tempBt;
  615. }else{
  616. if(firstKey != null && firstKey !=""){
  617. var tempBt;
  618. var x;
  619. tempBt = tempByte;
  620. for(x = 0;x < firstLength ;x ++){
  621. tempBt = enc(tempBt,firstKeyBt[x]);
  622. }
  623. encByte = tempBt;
  624. }
  625. }
  626. }
  627. encData += bt64ToHex(encByte);
  628. }
  629. if(remainder > 0){
  630. var remainderData = data.substring(iterator*4+0,leng);
  631. var tempByte = strToBt(remainderData);
  632. var encByte ;
  633. if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
  634. var tempBt;
  635. var x,y,z;
  636. tempBt = tempByte;
  637. for(x = 0;x < firstLength ;x ++){
  638. tempBt = enc(tempBt,firstKeyBt[x]);
  639. }
  640. for(y = 0;y < secondLength ;y ++){
  641. tempBt = enc(tempBt,secondKeyBt[y]);
  642. }
  643. for(z = 0;z < thirdLength ;z ++){
  644. tempBt = enc(tempBt,thirdKeyBt[z]);
  645. }
  646. encByte = tempBt;
  647. }else{
  648. if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
  649. var tempBt;
  650. var x,y;
  651. tempBt = tempByte;
  652. for(x = 0;x < firstLength ;x ++){
  653. tempBt = enc(tempBt,firstKeyBt[x]);
  654. }
  655. for(y = 0;y < secondLength ;y ++){
  656. tempBt = enc(tempBt,secondKeyBt[y]);
  657. }
  658. encByte = tempBt;
  659. }else{
  660. if(firstKey != null && firstKey !=""){
  661. var tempBt;
  662. var x;
  663. tempBt = tempByte;
  664. for(x = 0;x < firstLength ;x ++){
  665. tempBt = enc(tempBt,firstKeyBt[x]);
  666. }
  667. encByte = tempBt;
  668. }
  669. }
  670. }
  671. encData += bt64ToHex(encByte);
  672. }
  673. }
  674. }
  675. return encData;
  676. }
  677. '''
  678. def encode_info(plaintext):
  679. node_model_path = "/usr/lib/node_modules"
  680. ctx = execjs.compile(js_str)
  681. res = ctx.call('strEnc',plaintext)
  682. return res
  683. if __name__ == '__main__':
  684. print(encode_info("2447016584bf865cbe60"))