字符串加密的代码
总觉得第19行可以用var keyCoded = pkey.charCodeAt(pkey.length-1)代替
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="utf-8"> 5 <title>CALL语句</title> 6 7 <script lang="javascript"> 8 var msgCoded; 9 var msgEncoded; 10 11 function CodeAndEncode(pkey, date) 12 { 13 var codeStr = ""; 14 for (i in date) 15 { 16 var dateCoded; 17 for (j in pkey) 18 { 19 var keyCoded = pkey.charCodeAt(j); 20 var dateCoded = date.charCodeAt(i) ^ keyCoded; 21 } 22 codeStr += String.fromCharCode(dateCoded); 23 } 24 return codeStr; 25 } 26 function BtnCode_onclick() 27 { 28 var date = TextArea1.value; 29 var key = Password1.value; 30 msgCoded = CodeAndEncode(key, date); 31 TextArea1.value = msgCoded; 32 } 33 function BtnEncode_onclick() 34 { 35 var date = TextArea1.value; 36 var key = Password1.value; 37 msgEncoded = CodeAndEncode(key, date); 38 TextArea1.value = msgEncoded; 39 } 40 </script> 41 </head> 42 <body> 43 <textarea id="TextArea1" style="width:331px; height:211px"></textarea> 44  <br/> 45 密钥: 46 <input id="Password1" type="password" /> 47 <input id="BtnCode" type="button" value="加密" onclick="BtnCode_onclick()" 48 style="width:57px" /> 49 <input id="BtnEnCode" type="button" value="解密" onclick="BtnEncode_onclick()" 50 style="width:55px" /> 51 52 </body> 53 </html>