Advertisement
Guest User

Script

a guest
Sep 26th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getRandom( min, max ) {
  2.         if( min > max ) {
  3.                 return( -1 );
  4.         }
  5.         if( min == max ) {
  6.                 return( min );
  7.         }
  8.  
  9.     return( min + parseInt( Math.random() * ( max-min+1 ) ) );
  10. }
  11.  
  12. /*
  13.   Synchronous xmlHttpRequest/POST:
  14. */
  15. function xmlhttpPost(url, params) {
  16.         var xmlHttp = null;
  17.         try {
  18.             // Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
  19.             xmlHttp = new XMLHttpRequest();
  20.         } catch(e) {
  21.             try {
  22.                 // MS Internet Explorer (ab v6)
  23.                 xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
  24.             } catch(e) {
  25.                 try {
  26.                     // MS Internet Explorer (ab v5)
  27.                     xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
  28.                 } catch(e) {
  29.                     xmlHttp  = null;
  30.                 }
  31.             }
  32.         }
  33.         if (xmlHttp) {
  34.             xmlHttp.open('POST', url, false);
  35.                 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  36.                 xmlHttp.setRequestHeader("Content-length", params.length);
  37.                 xmlHttp.setRequestHeader("Connection", "close");
  38.             xmlHttp.send(params);
  39.             return xmlHttp.responseText;
  40.         } else {
  41.                 return false;
  42.         }
  43.  
  44. }
  45.  
  46.  
  47.  
  48. /*
  49. INPUTS (Oakley Group 2)
  50. */
  51. p = "FFFFFFFF"+ "FFFFFFFF"+     "C90FDAA2"+     "2168C234"+     "C4C6628B"+     "80DC1CD1"+
  52.         "29024E08"+     "8A67CC74"+     "020BBEA6"+ "3B139B22"+ "514A0879"+     "8E3404DD"+
  53.         "EF9519B3"+ "CD3A431B"+ "302B0A6D"+ "F25F1437"+ "4FE1356D"+ "6D51C245"+
  54.         "E485B576"+ "625E7EC6"+ "F44C42E9"+ "A637ED6B"+ "0BFF5CB6"+ "F406B7ED"+
  55.         "EE386BFB"+ "5A899FA5"+ "AE9F2411"+ "7C4B1FE6"+ "49286651"+ "ECE65381"+
  56.         "FFFFFFFF"+ "FFFFFFFF";
  57. g = "2";
  58.  
  59.  
  60. function send() {
  61.         document.getElementById("success").style.display = "none";              
  62.         msgwdw = document.getElementById("messageWindow");
  63.         if (msgwdw == null) {
  64.                 debug = false;
  65.         } else {
  66.                 debug = true;
  67.         }
  68.         frmSubject = document.getElementById("subject").value;
  69.         frmFrom = document.getElementById("senderName").value;
  70.        
  71.         // generate random r
  72.         randomValue = new Clipperz.ByteArray();
  73.         iv = new Clipperz.ByteArray();
  74.         ctr = "";
  75.         c = (128/8)
  76.         for (i=0; i<c ; i++) {
  77.                 randomValue.appendByte(getRandom(0, 255));
  78.                 iv.appendByte(getRandom(0, 255));
  79.         }
  80.         for (i = 0; i < 8; i++) {
  81.                 ctr += getRandom(48, 57)        
  82.         }
  83.        
  84.         if (debug) msgwdw.innerHTML = "<strong>Own random:</strong><br /> "+randomValue.toHexString()+"<br />";
  85.        
  86.         // calculate dhU = g^r mod p
  87.         pB = new Clipperz.Crypto.BigInt(p,16);
  88.         gB = new Clipperz.Crypto.BigInt(g,10);
  89.         randomB = new Clipperz.Crypto.BigInt(randomValue.toHexString(),16);    
  90.        
  91.         dhUB = gB.powerModule(randomB, pB);
  92.  
  93.         // Send dhU and reqeust dhS
  94.         dhSx = xmlhttpPost("securecontactform_rcv_en.jsp","type=getDH&dhU="+dhUB.asString(16)+"&ctr="+ctr+"&name="+frmFrom+"&subject="+frmSubject);
  95.        
  96.         if (debug) msgwdw.innerHTML = msgwdw.innerHTML+"<strong>Sent dhU:</strong><br /> 0x"+dhUB.asString(16)+"<br />";
  97.  
  98.         // calculate k = dhS^r mod p
  99.         dhSB = new Clipperz.Crypto.BigInt(dhSx, 16);
  100.         dhSB = new Clipperz.Crypto.BigInt("0x"+dhSx, 16);
  101.         if (debug) msgwdw.innerHTML = msgwdw.innerHTML+"<strong>Received dhS:</strong><br /> 0x"+dhSB.asString(16)+"<br />";
  102.        
  103.         dhB = dhSB.powerModule(randomB, pB);
  104.         dh = "0x"+dhB.asString(16);
  105.         if (debug) msgwdw.innerHTML = msgwdw.innerHTML+"<strong>dh:</strong><br /> 0x"+dhB.asString(16)+"<br />";
  106.                
  107.         kS = dh.substr(0,34)
  108.        
  109.         // encryypt message c = aes(m,k) (128bit, mode: ofb)    
  110.         key = new Clipperz.ByteArray(kS,16);
  111.         if (debug) msgwdw.innerHTML = msgwdw.innerHTML+"<strong>AES key:</strong><br /> "+kS+"<br />";
  112.  
  113.        
  114.         plainText = document.getElementById("message").value;
  115.         if (debug) msgwdw.innerHTML = msgwdw.innerHTML+"<strong>Plaintext:</strong><br /> "+plainText+"<br />";
  116.  
  117.         plainByte = new Clipperz.ByteArray(plainText);
  118.         for (i=(plainByte.length() % 16); i<16 && i != 0;i++)  {
  119.                 plainByte.appendByte("0");
  120.         }
  121.        
  122.         numBlocks = Math.ceil(plainByte.length()/16)
  123.         ivOrig = iv.clone();
  124.         encPlain = new Clipperz.ByteArray();
  125.         for (i = 0; i < numBlocks; i++) {              
  126.                
  127.                 iv = new Clipperz.ByteArray(
  128.                         Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}),
  129.                         iv.arrayValues()));
  130.                        
  131.                 for (j=0; j<16; j++) {
  132.                         encPlain.appendByte(iv.byteAtIndex(j) ^ plainByte.byteAtIndex((i*16)+j));
  133.                 }
  134.         }
  135.         //Send encrypted message        
  136.         xmlhttpPost("securecontactform_rcv_en.jsp","type=recvMsg&msg="+encPlain.toHexString().substr(2)+"&iv="+ivOrig.toHexString().substr(2));
  137.  
  138.         if (debug) msgwdw.innerHTML = msgwdw.innerHTML+"<strong>Sent encrypted message: </strong><br />"+numBlocks+"Blocks/ "+encPlain.length()+"Bytes/ "+encPlain.toHexString()+"<br />";
  139.        
  140.        
  141.         document.getElementById("success").style.display = "inline";
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement