开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 1235|回复: 5
收起左侧

[已解决] DES加密的JS文件,如何解密

 关闭 [复制链接]
结帖率:93% (13/14)
发表于 2021-8-25 15:39:08 | 显示全部楼层 |阅读模式   浙江省金华市
200精币
有上有一份DES加密字符串的JS源码。字符串加密成功后想进行解密,就是找不到解密的函数。
希望高手帮忙看下,源码中有没有带解密的函数,要如何调用。
附上JS文件
DES内容.txt (22.71 KB, 下载次数: 10)

最佳答案

查看完整内容

deString('') 解密

回答提醒:如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至 源码区 可获得加分喔。
友情提醒:本版被采纳的主题可在 申请荣誉值 页面申请荣誉值,获得 1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。
快捷通道:申请荣誉值无答案申请取消悬赏投诉有答案未采纳为最佳
结帖率:100% (1/1)

签到天数: 8 天

发表于 2021-8-25 15:39:09 | 显示全部楼层   福建省厦门市
deString('') 解密

  1. function enString(data){
  2. var key1 = "YHXWWLKJYXGS";
  3. var key2 = "ZFCHHYXFL10C";
  4. var key3 = "DES";
  5. var enchex = strEnc(data,key1,key2,key3);
  6. return enchex;
  7. }
  8. function deString(data){
  9. var key1 = "YHXWWLKJYXGS";
  10. var key2 = "ZFCHHYXFL10C";
  11. var key3 = "DES";
  12. var enchex = strDec(data,key1,key2,key3);
  13. return enchex;
  14. }
  15. /*
  16. * encrypt the string to string made up of hex
  17. * return the encrypted string
  18. */
  19. function strEnc(data,firstKey,secondKey,thirdKey){

  20. var leng = data.length;
  21. var encData = "";
  22. var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
  23. if(firstKey != null && firstKey != ""){   
  24.    firstKeyBt = getKeyBytes(firstKey);
  25.    firstLength = firstKeyBt.length;
  26. }
  27. if(secondKey != null && secondKey != ""){
  28.    secondKeyBt = getKeyBytes(secondKey);
  29.    secondLength = secondKeyBt.length;
  30. }
  31. if(thirdKey != null && thirdKey != ""){
  32.    thirdKeyBt = getKeyBytes(thirdKey);
  33.    thirdLength = thirdKeyBt.length;
  34. }  

  35. if(leng > 0){
  36.    if(leng < 4){
  37.      var bt = strToBt(data);      
  38.      var encByte ;
  39.      if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
  40.        var tempBt;
  41.        var x,y,z;
  42.        tempBt = bt;        
  43.        for(x = 0;x < firstLength ;x ++){
  44.          tempBt = enc(tempBt,firstKeyBt[x]);
  45.        }
  46.        for(y = 0;y < secondLength ;y ++){
  47.          tempBt = enc(tempBt,secondKeyBt[y]);
  48.        }
  49.        for(z = 0;z < thirdLength ;z ++){
  50.          tempBt = enc(tempBt,thirdKeyBt[z]);
  51.        }        
  52.        encByte = tempBt;        
  53.      }else{
  54.        if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
  55.          var tempBt;
  56.          var x,y;
  57.          tempBt = bt;
  58.          for(x = 0;x < firstLength ;x ++){
  59.            tempBt = enc(tempBt,firstKeyBt[x]);
  60.          }
  61.          for(y = 0;y < secondLength ;y ++){
  62.            tempBt = enc(tempBt,secondKeyBt[y]);
  63.          }
  64.          encByte = tempBt;
  65.        }else{
  66.          if(firstKey != null && firstKey !=""){            
  67.            var tempBt;
  68.            var x = 0;
  69.            tempBt = bt;            
  70.            for(x = 0;x < firstLength ;x ++){
  71.              tempBt = enc(tempBt,firstKeyBt[x]);
  72.            }
  73.            encByte = tempBt;
  74.          }
  75.        }        
  76.      }
  77.      encData = bt64ToHex(encByte);
  78.    }else{
  79.      var iterator = parseInt(leng/4);
  80.      var remainder = leng%4;
  81.      var i=0;      
  82.      for(i = 0;i < iterator;i++){
  83.        var tempData = data.substring(i*4+0,i*4+4);
  84.        var tempByte = strToBt(tempData);
  85.        var encByte ;
  86.        if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
  87.          var tempBt;
  88.          var x,y,z;
  89.          tempBt = tempByte;
  90.          for(x = 0;x < firstLength ;x ++){
  91.            tempBt = enc(tempBt,firstKeyBt[x]);
  92.          }
  93.          for(y = 0;y < secondLength ;y ++){
  94.            tempBt = enc(tempBt,secondKeyBt[y]);
  95.          }
  96.          for(z = 0;z < thirdLength ;z ++){
  97.            tempBt = enc(tempBt,thirdKeyBt[z]);
  98.          }
  99.          encByte = tempBt;
  100.        }else{
  101.          if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
  102.            var tempBt;
  103.            var x,y;
  104.            tempBt = tempByte;
  105.            for(x = 0;x < firstLength ;x ++){
  106.              tempBt = enc(tempBt,firstKeyBt[x]);
  107.            }
  108.            for(y = 0;y < secondLength ;y ++){
  109.              tempBt = enc(tempBt,secondKeyBt[y]);
  110.            }
  111.            encByte = tempBt;
  112.          }else{
  113.            if(firstKey != null && firstKey !=""){                     
  114.              var tempBt;
  115.              var x;
  116.              tempBt = tempByte;
  117.              for(x = 0;x < firstLength ;x ++){               
  118.                tempBt = enc(tempBt,firstKeyBt[x]);
  119.              }
  120.              encByte = tempBt;              
  121.            }
  122.          }
  123.        }
  124.        encData += bt64ToHex(encByte);
  125.      }      
  126.      if(remainder > 0){
  127.        var remainderData = data.substring(iterator*4+0,leng);
  128.        var tempByte = strToBt(remainderData);
  129.        var encByte ;
  130.        if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
  131.          var tempBt;
  132.          var x,y,z;
  133.          tempBt = tempByte;
  134.          for(x = 0;x < firstLength ;x ++){
  135.            tempBt = enc(tempBt,firstKeyBt[x]);
  136.          }
  137.          for(y = 0;y < secondLength ;y ++){
  138.            tempBt = enc(tempBt,secondKeyBt[y]);
  139.          }
  140.          for(z = 0;z < thirdLength ;z ++){
  141.            tempBt = enc(tempBt,thirdKeyBt[z]);
  142.          }
  143.          encByte = tempBt;
  144.        }else{
  145.          if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
  146.            var tempBt;
  147.            var x,y;
  148.            tempBt = tempByte;
  149.            for(x = 0;x < firstLength ;x ++){
  150.              tempBt = enc(tempBt,firstKeyBt[x]);
  151.            }
  152.            for(y = 0;y < secondLength ;y ++){
  153.              tempBt = enc(tempBt,secondKeyBt[y]);
  154.            }
  155.            encByte = tempBt;
  156.          }else{
  157.            if(firstKey != null && firstKey !=""){            
  158.              var tempBt;
  159.              var x;
  160.              tempBt = tempByte;
  161.              for(x = 0;x < firstLength ;x ++){
  162.                tempBt = enc(tempBt,firstKeyBt[x]);
  163.              }
  164.              encByte = tempBt;
  165.            }
  166.          }
  167.        }
  168.        encData += bt64ToHex(encByte);
  169.      }               
  170.    }
  171. }
  172. return encData;
  173. }

  174. /*
  175. * decrypt the encrypted string to the original string
  176. *
  177. * return  the original string  
  178. */
  179. function strDec(data,firstKey,secondKey,thirdKey){
  180. var leng = data.length;
  181. var decStr = "";
  182. var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
  183. if(firstKey != null && firstKey != ""){   
  184.    firstKeyBt = getKeyBytes(firstKey);
  185.    firstLength = firstKeyBt.length;
  186. }
  187. if(secondKey != null && secondKey != ""){
  188.    secondKeyBt = getKeyBytes(secondKey);
  189.    secondLength = secondKeyBt.length;
  190. }
  191. if(thirdKey != null && thirdKey != ""){
  192.    thirdKeyBt = getKeyBytes(thirdKey);
  193.    thirdLength = thirdKeyBt.length;
  194. }

  195. var iterator = parseInt(leng/16);
  196. var i=0;  
  197. for(i = 0;i < iterator;i++){
  198.    var tempData = data.substring(i*16+0,i*16+16);   
  199.    var strByte = hexToBt64(tempData);   
  200.    var intByte = new Array(64);
  201.    var j = 0;
  202.    for(j = 0;j < 64; j++){
  203.      intByte[j] = parseInt(strByte.substring(j,j+1));
  204.    }   
  205.    var decByte;
  206.    if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
  207.      var tempBt;
  208.      var x,y,z;
  209.      tempBt = intByte;
  210.      for(x = thirdLength - 1;x >= 0;x --){
  211.        tempBt = dec(tempBt,thirdKeyBt[x]);
  212.      }
  213.      for(y = secondLength - 1;y >= 0;y --){
  214.        tempBt = dec(tempBt,secondKeyBt[y]);
  215.      }
  216.      for(z = firstLength - 1;z >= 0 ;z --){
  217.        tempBt = dec(tempBt,firstKeyBt[z]);
  218.      }
  219.      decByte = tempBt;
  220.    }else{
  221.      if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
  222.        var tempBt;
  223.        var x,y,z;
  224.        tempBt = intByte;
  225.        for(x = secondLength - 1;x >= 0 ;x --){
  226.          tempBt = dec(tempBt,secondKeyBt[x]);
  227.        }
  228.        for(y = firstLength - 1;y >= 0 ;y --){
  229.          tempBt = dec(tempBt,firstKeyBt[y]);
  230.        }
  231.        decByte = tempBt;
  232.      }else{
  233.        if(firstKey != null && firstKey !=""){
  234.          var tempBt;
  235.          var x,y,z;
  236.          tempBt = intByte;
  237.          for(x = firstLength - 1;x >= 0 ;x --){
  238.            tempBt = dec(tempBt,firstKeyBt[x]);
  239.          }
  240.          decByte = tempBt;
  241.        }
  242.      }
  243.    }
  244.    decStr += byteToString(decByte);
  245. }      
  246. return decStr;
  247. }
  248. /*
  249. * chang the string into the bit array
  250. *
  251. * return bit array(it's length % 64 = 0)
  252. */
  253. function getKeyBytes(key){
  254. var keyBytes = new Array();
  255. var leng = key.length;
  256. var iterator = parseInt(leng/4);
  257. var remainder = leng%4;
  258. var i = 0;
  259. for(i = 0;i < iterator; i ++){
  260.    keyBytes[i] = strToBt(key.substring(i*4+0,i*4+4));
  261. }
  262. if(remainder > 0){
  263.    keyBytes[i] = strToBt(key.substring(i*4+0,leng));
  264. }   
  265. return keyBytes;
  266. }

  267. /*
  268. * chang the string(it's length <= 4) into the bit array
  269. *
  270. * return bit array(it's length = 64)
  271. */
  272. function strToBt(str){  
  273. var leng = str.length;
  274. var bt = new Array(64);
  275. if(leng < 4){
  276.    var i=0,j=0,p=0,q=0;
  277.    for(i = 0;i<leng;i++){
  278.      var k = str.charCodeAt(i);
  279.      for(j=0;j<16;j++){      
  280.        var pow=1,m=0;
  281.        for(m=15;m>j;m--){
  282.          pow *= 2;
  283.        }        
  284.        bt[16*i+j]=parseInt(k/pow)%2;
  285.      }
  286.    }
  287.    for(p = leng;p<4;p++){
  288.      var k = 0;
  289.      for(q=0;q<16;q++){      
  290.        var pow=1,m=0;
  291.        for(m=15;m>q;m--){
  292.          pow *= 2;
  293.        }        
  294.        bt[16*p+q]=parseInt(k/pow)%2;
  295.      }
  296.    }  
  297. }else{
  298.    for(i = 0;i<4;i++){
  299.      var k = str.charCodeAt(i);
  300.      for(j=0;j<16;j++){      
  301.        var pow=1;
  302.        for(m=15;m>j;m--){
  303.          pow *= 2;
  304.        }        
  305.        bt[16*i+j]=parseInt(k/pow)%2;
  306.      }
  307.    }  
  308. }
  309. return bt;
  310. }

  311. /*
  312. * chang the bit(it's length = 4) into the hex
  313. *
  314. * return hex
  315. */
  316. function bt4ToHex(binary) {
  317. var hex;
  318. switch (binary) {
  319.    case "0000" : hex = "0"; break;
  320.    case "0001" : hex = "1"; break;
  321.    case "0010" : hex = "2"; break;
  322.    case "0011" : hex = "3"; break;
  323.    case "0100" : hex = "4"; break;
  324.    case "0101" : hex = "5"; break;
  325.    case "0110" : hex = "6"; break;
  326.    case "0111" : hex = "7"; break;
  327.    case "1000" : hex = "8"; break;
  328.    case "1001" : hex = "9"; break;
  329.    case "1010" : hex = "A"; break;
  330.    case "1011" : hex = "B"; break;
  331.    case "1100" : hex = "C"; break;
  332.    case "1101" : hex = "D"; break;
  333.    case "1110" : hex = "E"; break;
  334.    case "1111" : hex = "F"; break;
  335. }
  336. return hex;
  337. }

  338. /*
  339. * chang the hex into the bit(it's length = 4)
  340. *
  341. * return the bit(it's length = 4)
  342. */
  343. function hexToBt4(hex) {
  344. var binary;
  345. switch (hex) {
  346.    case "0" : binary = "0000"; break;
  347.    case "1" : binary = "0001"; break;
  348.    case "2" : binary = "0010"; break;
  349.    case "3" : binary = "0011"; break;
  350.    case "4" : binary = "0100"; break;
  351.    case "5" : binary = "0101"; break;
  352.    case "6" : binary = "0110"; break;
  353.    case "7" : binary = "0111"; break;
  354.    case "8" : binary = "1000"; break;
  355.    case "9" : binary = "1001"; break;
  356.    case "A" : binary = "1010"; break;
  357.    case "B" : binary = "1011"; break;
  358.    case "C" : binary = "1100"; break;
  359.    case "D" : binary = "1101"; break;
  360.    case "E" : binary = "1110"; break;
  361.    case "F" : binary = "1111"; break;
  362. }
  363. return binary;
  364. }

  365. /*
  366. * chang the bit(it's length = 64) into the string
  367. *
  368. * return string
  369. */
  370. function byteToString(byteData){
  371. var str="";
  372. for(i = 0;i<4;i++){
  373.    var count=0;
  374.    for(j=0;j<16;j++){        
  375.      var pow=1;
  376.      for(m=15;m>j;m--){
  377.        pow*=2;
  378.      }              
  379.      count+=byteData[16*i+j]*pow;
  380.    }        
  381.    if(count != 0){
  382.      str+=String.fromCharCode(count);
  383.    }
  384. }
  385. return str;
  386. }

  387. function bt64ToHex(byteData){
  388. var hex = "";
  389. for(i = 0;i<16;i++){
  390.    var bt = "";
  391.    for(j=0;j<4;j++){   
  392.      bt += byteData[i*4+j];
  393.    }   
  394.    hex+=bt4ToHex(bt);
  395. }
  396. return hex;
  397. }

  398. function hexToBt64(hex){
  399. var binary = "";
  400. for(i = 0;i<16;i++){
  401.    binary+=hexToBt4(hex.substring(i,i+1));
  402. }
  403. return binary;
  404. }

  405. /*
  406. * the 64 bit des core arithmetic
  407. */

  408. function enc(dataByte,keyByte){  
  409. var keys = generateKeys(keyByte);   
  410. var ipByte   = initPermute(dataByte);  
  411. var ipLeft   = new Array(32);
  412. var ipRight  = new Array(32);
  413. var tempLeft = new Array(32);
  414. var i = 0,j = 0,k = 0,m = 0, n = 0;
  415. for(k = 0;k < 32;k ++){
  416.    ipLeft[k] = ipByte[k];
  417.    ipRight[k] = ipByte[32+k];
  418. }   
  419. for(i = 0;i < 16;i ++){
  420.    for(j = 0;j < 32;j ++){
  421.      tempLeft[j] = ipLeft[j];
  422.      ipLeft[j] = ipRight[j];      
  423.    }  
  424.    var key = new Array(48);
  425.    for(m = 0;m < 48;m ++){
  426.      key[m] = keys[i][m];
  427.    }
  428.    var  tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);      
  429.    for(n = 0;n < 32;n ++){
  430.      ipRight[n] = tempRight[n];
  431.    }  
  432.    
  433. }  


  434. var finalData =new Array(64);
  435. for(i = 0;i < 32;i ++){
  436.    finalData[i] = ipRight[i];
  437.    finalData[32+i] = ipLeft[i];
  438. }
  439. return finallyPermute(finalData);  
  440. }

  441. function dec(dataByte,keyByte){  
  442. var keys = generateKeys(keyByte);   
  443. var ipByte   = initPermute(dataByte);  
  444. var ipLeft   = new Array(32);
  445. var ipRight  = new Array(32);
  446. var tempLeft = new Array(32);
  447. var i = 0,j = 0,k = 0,m = 0, n = 0;
  448. for(k = 0;k < 32;k ++){
  449.    ipLeft[k] = ipByte[k];
  450.    ipRight[k] = ipByte[32+k];
  451. }  
  452. for(i = 15;i >= 0;i --){
  453.    for(j = 0;j < 32;j ++){
  454.      tempLeft[j] = ipLeft[j];
  455.      ipLeft[j] = ipRight[j];      
  456.    }  
  457.    var key = new Array(48);
  458.    for(m = 0;m < 48;m ++){
  459.      key[m] = keys[i][m];
  460.    }
  461.    
  462.    var  tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);      
  463.    for(n = 0;n < 32;n ++){
  464.      ipRight[n] = tempRight[n];
  465.    }  
  466. }  


  467. var finalData =new Array(64);
  468. for(i = 0;i < 32;i ++){
  469.    finalData[i] = ipRight[i];
  470.    finalData[32+i] = ipLeft[i];
  471. }
  472. return finallyPermute(finalData);  
  473. }

  474. function initPermute(originalData){
  475. var ipByte = new Array(64);
  476. for (i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) {
  477.    for (j = 7, k = 0; j >= 0; j--, k++) {
  478.      ipByte[i * 8 + k] = originalData[j * 8 + m];
  479.      ipByte[i * 8 + k + 32] = originalData[j * 8 + n];
  480.    }
  481. }   
  482. return ipByte;
  483. }

  484. function expandPermute(rightData){  
  485. var epByte = new Array(48);
  486. for (i = 0; i < 8; i++) {
  487.    if (i == 0) {
  488.      epByte[i * 6 + 0] = rightData[31];
  489.    } else {
  490.      epByte[i * 6 + 0] = rightData[i * 4 - 1];
  491.    }
  492.    epByte[i * 6 + 1] = rightData[i * 4 + 0];
  493.    epByte[i * 6 + 2] = rightData[i * 4 + 1];
  494.    epByte[i * 6 + 3] = rightData[i * 4 + 2];
  495.    epByte[i * 6 + 4] = rightData[i * 4 + 3];
  496.    if (i == 7) {
  497.      epByte[i * 6 + 5] = rightData[0];
  498.    } else {
  499.      epByte[i * 6 + 5] = rightData[i * 4 + 4];
  500.    }
  501. }      
  502. return epByte;
  503. }

  504. function xor(byteOne,byteTwo){  
  505. var xorByte = new Array(byteOne.length);
  506. for(i = 0;i < byteOne.length; i ++){      
  507.    xorByte[i] = byteOne[i] ^ byteTwo[i];
  508. }  
  509. return xorByte;
  510. }

  511. function sBoxPermute(expandByte){

  512.    var sBoxByte = new Array(32);
  513.    var binary = "";
  514.    var s1 = [
  515.        [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],
  516.        [0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],
  517.        [4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],
  518.        [15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 ]];

  519.        /* Table - s2 */
  520.    var s2 = [
  521.        [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],
  522.        [3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],
  523.        [0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],
  524.        [13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 ]];

  525.        /* Table - s3 */
  526.    var s3= [
  527.        [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],
  528.        [13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],
  529.        [13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],
  530.        [1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 ]];
  531.        /* Table - s4 */
  532.    var s4 = [
  533.        [7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],
  534.        [13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],
  535.        [10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],
  536.        [3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 ]];

  537.        /* Table - s5 */
  538.    var s5 = [
  539.        [2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],
  540.        [14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],
  541.        [4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],
  542.        [11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 ]];

  543.        /* Table - s6 */
  544.    var s6 = [
  545.        [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],
  546.        [10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],
  547.        [9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],
  548.        [4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 ]];

  549.        /* Table - s7 */
  550.    var s7 = [
  551.        [4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],
  552.        [13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],
  553.        [1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],
  554.        [6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]];

  555.        /* Table - s8 */
  556.    var s8 = [
  557.        [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
  558.        [1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
  559.        [7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
  560.        [2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]];
  561.    
  562.    for(m=0;m<8;m++){
  563.    var i=0,j=0;
  564.    i = expandByte[m*6+0]*2+expandByte[m*6+5];
  565.    j = expandByte[m * 6 + 1] * 2 * 2 * 2
  566.      + expandByte[m * 6 + 2] * 2* 2
  567.      + expandByte[m * 6 + 3] * 2
  568.      + expandByte[m * 6 + 4];
  569.    switch (m) {
  570.      case 0 :
  571.        binary = getBoxBinary(s1[i][j]);
  572.        break;
  573.      case 1 :
  574.        binary = getBoxBinary(s2[i][j]);
  575.        break;
  576.      case 2 :
  577.        binary = getBoxBinary(s3[i][j]);
  578.        break;
  579.      case 3 :
  580.        binary = getBoxBinary(s4[i][j]);
  581.        break;
  582.      case 4 :
  583.        binary = getBoxBinary(s5[i][j]);
  584.        break;
  585.      case 5 :
  586.        binary = getBoxBinary(s6[i][j]);
  587.        break;
  588.      case 6 :
  589.        binary = getBoxBinary(s7[i][j]);
  590.        break;
  591.      case 7 :
  592.        binary = getBoxBinary(s8[i][j]);
  593.        break;
  594.    }      
  595.    sBoxByte[m*4+0] = parseInt(binary.substring(0,1));
  596.    sBoxByte[m*4+1] = parseInt(binary.substring(1,2));
  597.    sBoxByte[m*4+2] = parseInt(binary.substring(2,3));
  598.    sBoxByte[m*4+3] = parseInt(binary.substring(3,4));
  599. }
  600. return sBoxByte;
  601. }

  602. function pPermute(sBoxByte){
  603. var pBoxPermute = new Array(32);
  604. pBoxPermute[ 0] = sBoxByte[15];
  605. pBoxPermute[ 1] = sBoxByte[ 6];
  606. pBoxPermute[ 2] = sBoxByte[19];
  607. pBoxPermute[ 3] = sBoxByte[20];
  608. pBoxPermute[ 4] = sBoxByte[28];
  609. pBoxPermute[ 5] = sBoxByte[11];
  610. pBoxPermute[ 6] = sBoxByte[27];
  611. pBoxPermute[ 7] = sBoxByte[16];
  612. pBoxPermute[ 8] = sBoxByte[ 0];
  613. pBoxPermute[ 9] = sBoxByte[14];
  614. pBoxPermute[10] = sBoxByte[22];
  615. pBoxPermute[11] = sBoxByte[25];
  616. pBoxPermute[12] = sBoxByte[ 4];
  617. pBoxPermute[13] = sBoxByte[17];
  618. pBoxPermute[14] = sBoxByte[30];
  619. pBoxPermute[15] = sBoxByte[ 9];
  620. pBoxPermute[16] = sBoxByte[ 1];
  621. pBoxPermute[17] = sBoxByte[ 7];
  622. pBoxPermute[18] = sBoxByte[23];
  623. pBoxPermute[19] = sBoxByte[13];
  624. pBoxPermute[20] = sBoxByte[31];
  625. pBoxPermute[21] = sBoxByte[26];
  626. pBoxPermute[22] = sBoxByte[ 2];
  627. pBoxPermute[23] = sBoxByte[ 8];
  628. pBoxPermute[24] = sBoxByte[18];
  629. pBoxPermute[25] = sBoxByte[12];
  630. pBoxPermute[26] = sBoxByte[29];
  631. pBoxPermute[27] = sBoxByte[ 5];
  632. pBoxPermute[28] = sBoxByte[21];
  633. pBoxPermute[29] = sBoxByte[10];
  634. pBoxPermute[30] = sBoxByte[ 3];
  635. pBoxPermute[31] = sBoxByte[24];   
  636. return pBoxPermute;
  637. }

  638. function finallyPermute(endByte){   
  639. var fpByte = new Array(64);  
  640. fpByte[ 0] = endByte[39];
  641. fpByte[ 1] = endByte[ 7];
  642. fpByte[ 2] = endByte[47];
  643. fpByte[ 3] = endByte[15];
  644. fpByte[ 4] = endByte[55];
  645. fpByte[ 5] = endByte[23];
  646. fpByte[ 6] = endByte[63];
  647. fpByte[ 7] = endByte[31];
  648. fpByte[ 8] = endByte[38];
  649. fpByte[ 9] = endByte[ 6];
  650. fpByte[10] = endByte[46];
  651. fpByte[11] = endByte[14];
  652. fpByte[12] = endByte[54];
  653. fpByte[13] = endByte[22];
  654. fpByte[14] = endByte[62];
  655. fpByte[15] = endByte[30];
  656. fpByte[16] = endByte[37];
  657. fpByte[17] = endByte[ 5];
  658. fpByte[18] = endByte[45];
  659. fpByte[19] = endByte[13];
  660. fpByte[20] = endByte[53];
  661. fpByte[21] = endByte[21];
  662. fpByte[22] = endByte[61];
  663. fpByte[23] = endByte[29];
  664. fpByte[24] = endByte[36];
  665. fpByte[25] = endByte[ 4];
  666. fpByte[26] = endByte[44];
  667. fpByte[27] = endByte[12];
  668. fpByte[28] = endByte[52];
  669. fpByte[29] = endByte[20];
  670. fpByte[30] = endByte[60];
  671. fpByte[31] = endByte[28];
  672. fpByte[32] = endByte[35];
  673. fpByte[33] = endByte[ 3];
  674. fpByte[34] = endByte[43];
  675. fpByte[35] = endByte[11];
  676. fpByte[36] = endByte[51];
  677. fpByte[37] = endByte[19];
  678. fpByte[38] = endByte[59];
  679. fpByte[39] = endByte[27];
  680. fpByte[40] = endByte[34];
  681. fpByte[41] = endByte[ 2];
  682. fpByte[42] = endByte[42];
  683. fpByte[43] = endByte[10];
  684. fpByte[44] = endByte[50];
  685. fpByte[45] = endByte[18];
  686. fpByte[46] = endByte[58];
  687. fpByte[47] = endByte[26];
  688. fpByte[48] = endByte[33];
  689. fpByte[49] = endByte[ 1];
  690. fpByte[50] = endByte[41];
  691. fpByte[51] = endByte[ 9];
  692. fpByte[52] = endByte[49];
  693. fpByte[53] = endByte[17];
  694. fpByte[54] = endByte[57];
  695. fpByte[55] = endByte[25];
  696. fpByte[56] = endByte[32];
  697. fpByte[57] = endByte[ 0];
  698. fpByte[58] = endByte[40];
  699. fpByte[59] = endByte[ 8];
  700. fpByte[60] = endByte[48];
  701. fpByte[61] = endByte[16];
  702. fpByte[62] = endByte[56];
  703. fpByte[63] = endByte[24];
  704. return fpByte;
  705. }

  706. function getBoxBinary(i) {
  707. var binary = "";
  708. switch (i) {
  709.    case 0 :binary = "0000";break;
  710.    case 1 :binary = "0001";break;
  711.    case 2 :binary = "0010";break;
  712.    case 3 :binary = "0011";break;
  713.    case 4 :binary = "0100";break;
  714.    case 5 :binary = "0101";break;
  715.    case 6 :binary = "0110";break;
  716.    case 7 :binary = "0111";break;
  717.    case 8 :binary = "1000";break;
  718.    case 9 :binary = "1001";break;
  719.    case 10 :binary = "1010";break;
  720.    case 11 :binary = "1011";break;
  721.    case 12 :binary = "1100";break;
  722.    case 13 :binary = "1101";break;
  723.    case 14 :binary = "1110";break;
  724.    case 15 :binary = "1111";break;
  725. }
  726. return binary;
  727. }
  728. /*
  729. * generate 16 keys for xor
  730. *
  731. */
  732. function generateKeys(keyByte){   
  733. var key   = new Array(56);
  734. var keys = new Array();  

  735. keys[ 0] = new Array();
  736. keys[ 1] = new Array();
  737. keys[ 2] = new Array();
  738. keys[ 3] = new Array();
  739. keys[ 4] = new Array();
  740. keys[ 5] = new Array();
  741. keys[ 6] = new Array();
  742. keys[ 7] = new Array();
  743. keys[ 8] = new Array();
  744. keys[ 9] = new Array();
  745. keys[10] = new Array();
  746. keys[11] = new Array();
  747. keys[12] = new Array();
  748. keys[13] = new Array();
  749. keys[14] = new Array();
  750. keys[15] = new Array();  
  751. var loop = [1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1];

  752. for(i=0;i<7;i++){
  753.    for(j=0,k=7;j<8;j++,k--){
  754.      key[i*8+j]=keyByte[8*k+i];
  755.    }
  756. }   

  757. var i = 0;
  758. for(i = 0;i < 16;i ++){
  759.    var tempLeft=0;
  760.    var tempRight=0;
  761.    for(j = 0; j < loop[i];j ++){         
  762.      tempLeft = key[0];
  763.      tempRight = key[28];
  764.      for(k = 0;k < 27 ;k ++){
  765.        key[k] = key[k+1];
  766.        key[28+k] = key[29+k];
  767.      }  
  768.      key[27]=tempLeft;
  769.      key[55]=tempRight;
  770.    }
  771.    var tempKey = new Array(48);
  772.    tempKey[ 0] = key[13];
  773.    tempKey[ 1] = key[16];
  774.    tempKey[ 2] = key[10];
  775.    tempKey[ 3] = key[23];
  776.    tempKey[ 4] = key[ 0];
  777.    tempKey[ 5] = key[ 4];
  778.    tempKey[ 6] = key[ 2];
  779.    tempKey[ 7] = key[27];
  780.    tempKey[ 8] = key[14];
  781.    tempKey[ 9] = key[ 5];
  782.    tempKey[10] = key[20];
  783.    tempKey[11] = key[ 9];
  784.    tempKey[12] = key[22];
  785.    tempKey[13] = key[18];
  786.    tempKey[14] = key[11];
  787.    tempKey[15] = key[ 3];
  788.    tempKey[16] = key[25];
  789.    tempKey[17] = key[ 7];
  790.    tempKey[18] = key[15];
  791.    tempKey[19] = key[ 6];
  792.    tempKey[20] = key[26];
  793.    tempKey[21] = key[19];
  794.    tempKey[22] = key[12];
  795.    tempKey[23] = key[ 1];
  796.    tempKey[24] = key[40];
  797.    tempKey[25] = key[51];
  798.    tempKey[26] = key[30];
  799.    tempKey[27] = key[36];
  800.    tempKey[28] = key[46];
  801.    tempKey[29] = key[54];
  802.    tempKey[30] = key[29];
  803.    tempKey[31] = key[39];
  804.    tempKey[32] = key[50];
  805.    tempKey[33] = key[44];
  806.    tempKey[34] = key[32];
  807.    tempKey[35] = key[47];
  808.    tempKey[36] = key[43];
  809.    tempKey[37] = key[48];
  810.    tempKey[38] = key[38];
  811.    tempKey[39] = key[55];
  812.    tempKey[40] = key[33];
  813.    tempKey[41] = key[52];
  814.    tempKey[42] = key[45];
  815.    tempKey[43] = key[41];
  816.    tempKey[44] = key[49];
  817.    tempKey[45] = key[35];
  818.    tempKey[46] = key[28];
  819.    tempKey[47] = key[31];
  820.    switch(i){
  821.      case 0: for(m=0;m < 48 ;m++){ keys[ 0][m] = tempKey[m]; } break;
  822.      case 1: for(m=0;m < 48 ;m++){ keys[ 1][m] = tempKey[m]; } break;
  823.      case 2: for(m=0;m < 48 ;m++){ keys[ 2][m] = tempKey[m]; } break;
  824.      case 3: for(m=0;m < 48 ;m++){ keys[ 3][m] = tempKey[m]; } break;
  825.      case 4: for(m=0;m < 48 ;m++){ keys[ 4][m] = tempKey[m]; } break;
  826.      case 5: for(m=0;m < 48 ;m++){ keys[ 5][m] = tempKey[m]; } break;
  827.      case 6: for(m=0;m < 48 ;m++){ keys[ 6][m] = tempKey[m]; } break;
  828.      case 7: for(m=0;m < 48 ;m++){ keys[ 7][m] = tempKey[m]; } break;
  829.      case 8: for(m=0;m < 48 ;m++){ keys[ 8][m] = tempKey[m]; } break;
  830.      case 9: for(m=0;m < 48 ;m++){ keys[ 9][m] = tempKey[m]; } break;
  831.      case 10: for(m=0;m < 48 ;m++){ keys[10][m] = tempKey[m]; } break;
  832.      case 11: for(m=0;m < 48 ;m++){ keys[11][m] = tempKey[m]; } break;
  833.      case 12: for(m=0;m < 48 ;m++){ keys[12][m] = tempKey[m]; } break;
  834.      case 13: for(m=0;m < 48 ;m++){ keys[13][m] = tempKey[m]; } break;
  835.      case 14: for(m=0;m < 48 ;m++){ keys[14][m] = tempKey[m]; } break;
  836.      case 15: for(m=0;m < 48 ;m++){ keys[15][m] = tempKey[m]; } break;
  837.    }
  838. }
  839. return keys;  
  840. }
复制代码

评分

参与人数 1荣誉 +1 收起 理由
笨潴 + 1 热心帮助他人,荣誉+1,希望继续努力(*^__^*) 嘻嘻!

查看全部评分

回复

使用道具 举报

结帖率:64% (16/25)

签到天数: 2 天

发表于 2021-8-25 15:48:23 | 显示全部楼层   江西省上饶市

小手一抖,精币到手
回复

使用道具 举报

结帖率:100% (33/33)

签到天数: 6 天

发表于 2021-8-25 15:54:49 | 显示全部楼层   陕西省渭南市
等大佬              
回复

使用道具 举报

结帖率:100% (1/1)

签到天数: 8 天

发表于 2021-8-25 16:08:42 | 显示全部楼层   福建省厦门市
直接贴代码居然要审核

附件试试

DES内容.txt (24.79 KB, 下载次数: 4)
回复

使用道具 举报

结帖率:60% (40/67)

签到天数: 1 天

发表于 2021-8-25 16:56:09 | 显示全部楼层   赤道几内亚
如此这般,给你源码
123.e (170.76 KB, 下载次数: 10)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表