home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / enc_sreb.rsp < prev    next >
Text File  |  1999-04-23  |  16KB  |  457 lines

  1. <!-- This is the default document/script used by SRE_B
  2.      shared-secret encryption algorithim of SRE-http.
  3.      You can customize the BODY of this,
  4.      but please note code that should NOT be modified -->
  5.  
  6.  <HTML>
  7.  <HEAD>
  8.  
  9.  
  10. <!-- ****************************** BEING NON-CHANGEABLE CODE ************** -->
  11. <SCRIPT>
  12. <!--
  13.  
  14. // DO NOT CHANGE THESE LINES (they are set dynamically!!! 
  15.     var nonce="##NONCE"            // the nonce
  16.     var hash16="##HASH_16"  // used for verification
  17.     var selector='##SELECTOR' // the selector
  18.     var servername='##SERVERNAME' // the server
  19.     var mimetype='##MIMETYPE'    // the mimetype 
  20.      ##ARRAY    // the escaped text to decrypt 
  21.  
  22. // these are globals
  23.   var ix=0 ; var iy=0 ; var iz=0  ; qclose=0
  24.  
  25. // ----------------------------------------------------
  26.  
  27. // ------------- do NOT modify this <SCRIPT>   
  28.  /*
  29.   *  md5.jvs 1.0b 27/06/96
  30.   *
  31.   * Javascript implementation of the RSA Data Security, Inc. MD5
  32.   * Message-Digest Algorithm.
  33.   *
  34.   * Copyright (c) 1996 Henri Torgemane. All Rights Reserved.
  35.   *
  36.   * Permission to use, copy, modify, and distribute this software
  37.   * and its documentation for any purposes and without
  38.   * fee is hereby granted provided that this copyright notice
  39.   * appears in all copies. 
  40.   *
  41.   * Of course, this soft is provided "as is" without express or implied
  42.   * warranty of any kind.
  43.   */
  44.  function array(n) {
  45.    for(i=0;i<n;i++) this[i]=0;
  46.    this.length=n; }
  47.  /* Some basic logical functions had to be rewritten because of a bug in
  48.   * Javascript.. Just try to compute 0xffffffff >> 4 with it..
  49.   * Of course, these functions are slower than the original would be, but
  50.   * at least, they work!
  51.   */
  52.  function integer(n) { return n%(0xffffffff+1); }
  53.  function shr(a,b) {
  54.    a=integer(a);
  55.    b=integer(b);
  56.    if (a-0x80000000>=0) {
  57.      a=a%0x80000000;
  58.      a>>=b;
  59.      a+=0x40000000>>(b-1);   } 
  60.    else
  61.      a>>=b;
  62.    return a; }
  63.  function shl1(a) {
  64.    a=a%0x80000000;
  65.    if (a&0x40000000==0x40000000)
  66.    {     a-=0x40000000;  
  67.      a*=2;
  68.      a+=0x80000000;  }
  69.    else
  70.      a*=2;
  71.    return a; }
  72.  function shl(a,b) {
  73.    a=integer(a);
  74.    b=integer(b);
  75.    for (var i=0;i<b;i++) a=shl1(a);
  76.    return a; }
  77.  function and(a,b) {
  78.    a=integer(a);
  79.    b=integer(b);
  80.    var t1=(a-0x80000000);
  81.    var t2=(b-0x80000000);
  82.    if (t1>=0) 
  83.      if (t2>=0) 
  84.        return ((t1&t2)+0x80000000);
  85.      else
  86.        return (t1&b);
  87.    else
  88.      if (t2>=0)
  89.        return (a&t2);
  90.      else
  91.        return (a&b);   }
  92.  function or(a,b) {
  93.    a=integer(a);
  94.    b=integer(b);
  95.    var t1=(a-0x80000000);
  96.    var t2=(b-0x80000000);
  97.    if (t1>=0) 
  98.      if (t2>=0) 
  99.        return ((t1|t2)+0x80000000);
  100.      else
  101.        return ((t1|b)+0x80000000);
  102.    else
  103.      if (t2>=0)
  104.        return ((a|t2)+0x80000000);
  105.      else
  106.        return (a|b);   }
  107.  function xor(a,b) {
  108.    a=integer(a);
  109.    b=integer(b);
  110.    var t1=(a-0x80000000);
  111.    var t2=(b-0x80000000);
  112.    if (t1>=0) 
  113.      if (t2>=0) 
  114.        return (t1^t2);
  115.      else
  116.        return ((t1^b)+0x80000000);
  117.    else
  118.      if (t2>=0)
  119.        return ((a^t2)+0x80000000);
  120.      else
  121.        return (a^b);   }
  122.  function not(a) {
  123.    a=integer(a);
  124.    return (0xffffffff-a); }
  125.  /* Here begin the real algorithm */
  126.      var state = new array(4); 
  127.      var count = new array(2);
  128.          count[0] = 0;
  129.          count[1] = 0;                     
  130.      var buffer = new array(64); 
  131.      var transformBuffer = new array(16); 
  132.      var digestBits = new array(16);
  133.      var S11 = 7;     var S12 = 12;     var S13 = 17;
  134.      var S14 = 22;     var S21 = 5;     var S22 = 9;
  135.      var S23 = 14;     var S24 = 20;     var S31 = 4;
  136.      var S32 = 11;     var S33 = 16;     var S34 = 23;
  137.      var S41 = 6;     var S42 = 10;     var S43 = 15;
  138.      var S44 = 21;
  139.      function F(x,y,z) {return or(and(x,y),and(not(x),z));     }
  140.      function G(x,y,z) {return or(and(x,z),and(y,not(z)));     }
  141.      function H(x,y,z) {return xor(xor(x,y),z);     }
  142.      function I(x,y,z) {return xor(y ,or(x , not(z)));     }
  143.      function rotateLeft(a,n) {return or(shl(a, n),(shr(a,(32 - n))));     }
  144.      function FF(a,b,c,d,x,s,ac) {
  145.          a = a+F(b, c, d) + x + ac;
  146.          a = rotateLeft(a, s);
  147.          a = a+b;
  148.          return a;     }
  149.      function GG(a,b,c,d,x,s,ac) {
  150.          a = a+G(b, c, d) +x + ac;
  151.          a = rotateLeft(a, s);
  152.          a = a+b;
  153.          return a;     }
  154.      function HH(a,b,c,d,x,s,ac) {
  155.          a = a+H(b, c, d) + x + ac;
  156.          a = rotateLeft(a, s);
  157.          a = a+b;
  158.          return a;     }
  159.      function II(a,b,c,d,x,s,ac) {
  160.          a = a+I(b, c, d) + x + ac;
  161.          a = rotateLeft(a, s);
  162.          a = a+b;
  163.          return a;     }
  164.      function transform(buf,offset) { 
  165.          var a=0, b=0, c=0, d=0; 
  166.          var x = transformBuffer;
  167.          a = state[0];
  168.          b = state[1];
  169.          c = state[2];
  170.          d = state[3];
  171.          for (i = 0; i < 16; i++) {
  172.              x[i] = and(buf[i*4+offset],0xff);
  173.              for (j = 1; j < 4; j++) {
  174.                  x[i]+=shl(and(buf[i*4+j+offset] ,0xff), j * 8);      }         }
  175.          /* Round 1 */
  176.          a = FF ( a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  177.          d = FF ( d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  178.          c = FF ( c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  179.          b = FF ( b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  180.          a = FF ( a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  181.          d = FF ( d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  182.          c = FF ( c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  183.          b = FF ( b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  184.          a = FF ( a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  185.          d = FF ( d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  186.          c = FF ( c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  187.          b = FF ( b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  188.          a = FF ( a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  189.          d = FF ( d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  190.          c = FF ( c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  191.          b = FF ( b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  192.          /* Round 2 */
  193.          a = GG ( a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  194.          d = GG ( d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  195.          c = GG ( c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  196.          b = GG ( b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  197.          a = GG ( a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  198.          d = GG ( d, a, b, c, x[10], S22,  0x2441453); /* 22 */
  199.          c = GG ( c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  200.          b = GG ( b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  201.          a = GG ( a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  202.          d = GG ( d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  203.          c = GG ( c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  204.          b = GG ( b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  205.          a = GG ( a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  206.          d = GG ( d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  207.          c = GG ( c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  208.          b = GG ( b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  209.          /* Round 3 */
  210.          a = HH ( a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  211.          d = HH ( d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  212.          c = HH ( c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  213.          b = HH ( b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  214.          a = HH ( a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  215.          d = HH ( d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  216.          c = HH ( c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  217.          b = HH ( b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  218.          a = HH ( a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  219.          d = HH ( d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  220.          c = HH ( c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  221.          b = HH ( b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
  222.          a = HH ( a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  223.          d = HH ( d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  224.          c = HH ( c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  225.          b = HH ( b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  226.          /* Round 4 */
  227.          a = II ( a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  228.          d = II ( d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  229.          c = II ( c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  230.          b = II ( b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  231.          a = II ( a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  232.          d = II ( d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  233.          c = II ( c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  234.          b = II ( b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  235.          a = II ( a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  236.          d = II ( d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  237.          c = II ( c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  238.          b = II ( b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  239.          a = II ( a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  240.          d = II ( d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  241.          c = II ( c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  242.          b = II ( b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  243.          state[0] +=a;
  244.          state[1] +=b;
  245.          state[2] +=c;
  246.          state[3] +=d;     }
  247.      function init() {
  248.          count[0]=count[1] = 0;
  249.          state[0] = 0x67452301;
  250.          state[1] = 0xefcdab89;
  251.          state[2] = 0x98badcfe;
  252.          state[3] = 0x10325476;
  253.          for (i = 0; i < digestBits.length; i++)
  254.              digestBits[i] = 0;     }
  255.      function update(b) { 
  256.          var index,i;
  257.          index = and(shr(count[0],3) , 0x3f);
  258.          if (count[0]<0xffffffff-7) 
  259.            count[0] += 8;
  260.          else {
  261.            count[1]++;
  262.            count[0]-=0xffffffff+1;
  263.            count[0]+=8;         }
  264.          buffer[index] = and(b,0xff);
  265.          if (index  >= 63) {
  266.              transform(buffer, 0);
  267.          }     }
  268.      function finish() {
  269.          var bits = new array(8);
  270.          var     padding; 
  271.          var     i=0, index=0, padLen=0;
  272.          for (i = 0; i < 4; i++) {
  273.              bits[i] = and(shr(count[0],(i * 8)), 0xff);         }
  274.          for (i = 0; i < 4; i++) {
  275.              bits[i+4]=and(shr(count[1],(i * 8)), 0xff);         }
  276.          index = and(shr(count[0], 3) ,0x3f);
  277.          padLen = (index < 56) ? (56 - index) : (120 - index);
  278.          padding = new array(64); 
  279.          padding[0] = 0x80;
  280.          for (i=0;i<padLen;i++)
  281.            update(padding[i]);
  282.          for (i=0;i<8;i++) 
  283.            update(bits[i]);
  284.          for (i = 0; i < 4; i++) {
  285.              for (j = 0; j < 4; j++) {
  286.                  digestBits[i*4+j] = and(shr(state[i], (j * 8)) , 0xff);             }
  287.          }      }
  288.  /* End of the MD5 algorithm */
  289.  function hexa(n) {
  290.   var hexa_h = "0123456789abcdef";  var hexa_c="";   var hexa_m=n;
  291.   for (hexa_i=0;hexa_i<8;hexa_i++) {
  292.     hexa_c=hexa_h.charAt(Math.abs(hexa_m)%16)+hexa_c;
  293.     hexa_m=Math.floor(hexa_m/16);  }
  294.   return hexa_c; }
  295.  
  296. function hextodec(ahex) {
  297.  var llen=ahex.length
  298.   ahex=ahex.toUpperCase()
  299.   var smm=0
  300.   var xlist='0123456789ABCDEF'
  301.    var afact=1
  302.    for (ir=llen-1; ir>=0;ir--) {
  303.        var acc=ahex.charAt(ir)
  304.        iind=xlist.indexOf(acc)   
  305.        smm=smm+(iind*afact)
  306.        afact=afact*16
  307.    }
  308.    return  smm
  309.  }
  310.  
  311.  
  312.  var ascii="01234567890123456789012345678901" +
  313.            " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"+
  314.            "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  315.  
  316.  function MD5(your_pwd)  {
  317.   var l,s,k,ka,kb,kc,kd;
  318.   init();
  319.   for (k=0;k<your_pwd.length;k++) {
  320.     l=your_pwd.charAt(k);
  321.     update(ascii.lastIndexOf(l));  }
  322.   finish();
  323.   ka=kb=kc=kd=0;
  324.   for (i=0;i<4;i++) ka+=shl(digestBits[15-i], (i*8));
  325.   for (i=4;i<8;i++) kb+=shl(digestBits[15-i], ((i-4)*8));
  326.   for (i=8;i<12;i++) kc+=shl(digestBits[15-i], ((i-8)*8));
  327.   for (i=12;i<16;i++) kd+=shl(digestBits[15-i], ((i-12)*8));
  328.   s=hexa(kd)+hexa(kc)+hexa(kb)+hexa(ka);
  329.   return s;  }
  330.  
  331.  function comp_md5(avalue,setit)
  332.    {aggx=avalue
  333.     if (setit==1){aggx=nonce + avalue}
  334.     zbb=aggx.toUpperCase()
  335.     zaa=MD5(zbb)
  336.    return zaa }
  337.  
  338.  
  339. // Random number generator
  340. function random3()
  341. ix=(171*ix)%30269
  342. iy=(172*iy)%30307
  343. iz=(170*iz)%30323
  344. var arandom=(ix/30269.) + (iy/30307.)  + (iz/30323)
  345. return Math.floor((arandom % 1.0)* 255)
  346. }
  347.  
  348. // Decryption, using md5 hash 
  349. // First, check for correct password
  350. function do_de_encrypt() {
  351.  document.askmd5.status.value='Computing MD5 encryption key'
  352.  themd5=comp_md5(document.askmd5.your_pwd.value,1)
  353.  document.askmd5.status.value='MD5 key computed! '
  354.  first16=themd5.substr(0,16)
  355.  cx=themd5.substr(29,3)
  356.  ix=hextodec(cx)
  357.  cy=themd5.substr(26,3)
  358.  iy=hextodec(cy)
  359.  cz=themd5.substr(24,2)
  360.  iz=hextodec(cz)
  361.  
  362.  first16=first16.toUpperCase()
  363.  if (first16!=hash16){
  364.     alert("Incorrect password. Please re-enter ")
  365.     document.askmd5.status.value='Incorrect password: please re-enter. '
  366.     return true; 
  367.  }
  368.  decwin=window.open("","")
  369.  decwin.document.open(mimetype)
  370.  document.askmd5.status.value='Writing decrypted contents... '
  371.  
  372.  for (i=0 ; i<kontents.length ; i++) {   // note use of array to avoid too long line problem
  373.     var aline=kontents[i]
  374.     damessage=''              // use a random # stream to decrypt
  375.     for (ii=0; ii<aline.length ;ii=ii+2) {
  376.        ahex=hextodec(aline.substr(ii,2))
  377.        rr=random3()
  378.        rr2=ahex^rr
  379.        newch=String.fromCharCode(rr2)
  380.       damessage=damessage + newch
  381.     } // for this line
  382.    decwin.document.write(damessage)
  383.    
  384.   if (i%40==1)
  385.     {document.askmd5.status.value='  done with ' + i*25 + ' (of '+kontents.length*25 +') bytes... '}
  386.  
  387.   }   // get next line
  388.   document.askmd5.status.value='Encryption has been completed.. You can CLICK here to close this window '
  389.   qclose=1  // enable the close capability of the status button
  390.  
  391.  return true
  392. }
  393.  
  394. function doclose()
  395. { if (qclose==0) { return true }
  396.   self.close()
  397.   return true ;
  398. }
  399.  
  400.  
  401.  
  402.  // -->
  403.  </SCRIPT>
  404.  
  405.  
  406. <!-- ****************************** End of NON-CHANGEABLE CODE ************** -->
  407. <!-- You can modify the remainder of the <HEAD> -->
  408.  
  409.  <TITLE>Decrypt response </TITLE>
  410.  
  411.  </HEAD>
  412.  
  413.  
  414. <!-- ================================================= -->
  415. <!-- You can modify the <BODY> of this document, except where noted -->
  416.  
  417. <BODY BGCOLOR="#FFFFFF">
  418.  
  419.  
  420.  
  421. <!-- Javascript required!
  422.      You can change the following if you want.
  423.      You can even convert it to HTML (and not use document.writeln)
  424.      but be sure to retain the onClick and onSubmit attributes
  425.  -->
  426. <script>
  427. document.writeln('<h2 align="center">The JavaScript Decrytor (for encrypted responses from an SRE-http server) </h2>')
  428. document.writeln('<tt>'+ servername + '/' + selector +'</tt>')
  429. document.writeln('has been encrypted. You can use this form to decrypt it.')
  430. document.writeln('<FORM name="askmd5" >')
  431. document.writeln(" Enter your <b>shared-secret</b> password:  ")
  432. document.writeln(' <INPUT type="text" name="your_pwd" value=""  size=20><br>')
  433. document.writeln(' <INPUT type="button" value="Click here to start decryption"')
  434. document.writeln('      onclick="do_de_encrypt() ; return true">')
  435. document.writeln('<hr width="30%"><b>Status:</b>')
  436. document.writeln('  <INPUT type="button" name="status" ')
  437. document.writeln('         value="Please enter your shared-secret password ............"')
  438. document.writeln('         onClick="doclose() ; return true"')
  439. document.writeln('>')
  440.  
  441. document.writeln('</FORM>')
  442. </script>
  443.  
  444. <noscript>
  445.    <blockquote>
  446.      Unfortunately, your browser does not support JavaScript -- 
  447.      you'll need to encrypt the document using a stand-alond program
  448.      (such as DE_SREA.CMD).
  449.     </blockquote>
  450. </noscript>
  451.  
  452.  
  453.  
  454. </body>  </HTML>
  455.  
  456.