<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>deom</title>
<script>
window.onload=function(){
var oText1 =document.getElementById('text1');
var oText2 =document.getElementById('text2');
var oBtn1 =document.getElementById('but1');
var oBtn2 =document.getElementById('but2');
//加密
oBtn1.onclick=function(){
var str =oText1.value;
var arr=[];
for(var i=0; i<str.length;i++){
var code =str.charCodeAt(i)+3;
arr.push(String.fromCharCode(code))
}
oText2.value =arr.join('');
}
//解密
oBtn2.onclick=function(){
var str ='';
for(var i=0; i<oText2.value.length;i++){
str += String.fromCharCode(oText2.value.charCodeAt(i)-3)
}
oText1.value =str;
}
}
</script>
</head>
<body>
<textarea id='text1' col='20' row='50'></textarea><br/>
<button id="but1">加密</button>
<button id="but2">解密</button><br/>
<textarea id='text2' col='20' row='50'></textarea>
</body>
</html>