WEB开发网
开发学院网页设计JavaScript js文本加密 将英文转成数字 阅读

js文本加密 将英文转成数字

 2009-05-07 20:11:26 来源:WEB开发网   
核心提示:<SCRipT LANGUAGE="javaScript"><!-- Beginvar str_in;var str_out = ""; var num_in;var num_out = "";var e = "Enter Text

<SCRipT LANGUAGE="javaScript">
<!-- Begin
var str_in;
var str_out = "";
var num_in;
var num_out = "";
var e = "Enter Text!";

function str_to_num(form) {
num_out = "";
if(form.input.value == "") alert(e);
else {
str_in = escape(form.input.value);
for(i = 0; i < str_in.length; i++) {
num_out += str_in.charCodeAt(i) - 23;
}
form.output.value = num_out;
form.input.value = "";
  }
}

function num_to_str(form) {
str_out = "";
if(form.output.value == "") alert(e)
else {
num_out = form.output.value; 
for(i = 0; i < num_out.length; i += 2) {
num_in = parseInt(num_out.substr(i,[2])) + 23;
num_in = unescape('%' + num_in.toString(16));
str_out += num_in;
}
form.input.value = unescape(str_out);
form.output.value = "";
  }
}
//  End -->
</script>
<center>
<form name=encryptform>
   <table>
    <tr>
     <td align=center>
      <input name=input type=text size=40 value="Javascript Fairyland">
     </td>
     <td align=center>
      <input type=button value="<--" >
      <br>
      <input type=button value="-->" >
     </td>
     <td align=center>
      <input name=output type=text size=40>
     </td>
    </tr>
   </table>
</form>
</center>

Tags:js 文本 加密

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接