HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Encoding - Decoding Text : Version 1.0 - m3Noa</title>
<style type="text/css">
.note {
font-size:10px;
color:#999999;
}
fieldset {
width:400px;
padding:5px;
border:#ccccee 1px solid;
text-align:center;
}
fieldset legend {
font-weight:bold;
color:#550066;
text-align:left;
}
</style>
<script type="text/javascript">
<!-- Begin
//###### THIS IS A HELP MESSAGE FUNCTION AND MUST NOT BE CHANGED ######
function help() {
var m1,m2,m3,m4,m5,h;
h=" __________ Encoder - Decoder Help __________\n\n";
m1="1) Nhập nội dung text vào khung text trên cùng."
m2="2) Nhấn nút [ Encode ] để tiến hành mã hóa. Code đã mã hóa sẽ hiện ra ở ô text thứ 2."
m3="3) Copy đoạn text mã hóa và send/mail cho bạn bè."
m4="4) Người nhận được mã phải nhập đoạn code vào ô text dưới cùng và nhấn nút [Decode] mới có thể đọc được nội dung ban đầu của đoạn text."
m5="5) Những người có sử dụng cùng một bộ mã hóa mới có thể sử dụng để trao đổi tin tức với nhau. Nếu có ý định sử dụng riêng thì bạn có thể dùng nó để mã hóa password, dấu nội dung các thông tin bí mật :D."
alert(h+m1+"\n"+m2+"\n"+m3+"\n"+m4+"\n"+m5);
}
//###### HELP MESSAGE FUNCTION ENDS HERE ######
var i,j;
var getc;
var len;
var num,alpha;
num=new Array("@#","#$","16","17","11","12","15","07","08","09","10","25","26","13","##","$$","18","19","20","21","22","!%","$*","%%","!!","23","24","01","02","14","00","03","04","05","06","^#","#*","$!","-%");
alpha=new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"," ",".",",","0","1","2","3","4","5","6","7","8","9");
/* Cẩn thận khi thay đổi các phần tử ở 2 mảng trên, vì thay đổi đó có thể làm sai lệch các đoạn mã hóa cũ. Bạn có thể chỉnh sửa, thêm bớt các thành phần, nhưng lưu ý là mỗi phần tử chỉ bao gồm 2 ký tự mà thôi. Số phần tử ở 2 mảng trên phải bằng nhau. */
//######## ENCODER FUNCTION STARTS HERE #########
function encode() {
len=document.f1.ta1.value.length;
document.f1.ta2.value="";
for(i=0;i<len;i++) {
getc=document.f1.ta1.value.charAt(i);
getc=getc.toLowerCase();
for(j=0;j<alpha.length;j++) {
if(alpha[j]==getc) {
document.f1.ta2.value+=num[j];
}
}
}
}
//######### ENCODER FUNCTION ENDS HERE ###########
//######### DECODER FUNCTION STARTS HERE #########
function decode() {
if ((document.f1.ta3.value == "") || (document.f1.ta3.value != document.f1.ta2.value) && (document.f1.ta2.value!= "")) document.f1.ta3.value = document.f1.ta2.value;
document.f1.ta2.value = document.f1.ta3.value;
document.f1.ta3.value = "";
len=document.f1.ta2.value.length;
for(i=0;i<len;i++) {
getc=document.f1.ta2.value.charAt(i)+document.f1.ta2.value.charAt(i+1);
i=i+1;
for(j=0;j<num.length;j++) {
if(num[j]==getc) {
document.f1.ta3.value+=alpha[j];
}
}
}
}
//####### DECODER FUNCTION ENDS HERE #######
// End -->
</script>
</head>
<BODY onload="javascript:document.f1.ta1.select();" style="font-family:Arial, Helvetica, sans-serif; color:#000000; font-size:12px;">
<div align="center" style="word-spacing:inherit;">
<form name="f1">
<fieldset><legend>Text Encoding</legend>Nhập đoạn text cần mã hóa vào ô bên dưới<br />
<span class="note">(Phiên bản hiện tại chưa sử dụng được các ký tự đặc biệt và chữ có dấu)</span>
<br>
<textarea cols="35" rows="5" name="ta1"></textarea><br>
<input type="button" name="b1" value=" Encode " onclick="encode();">
<input type="reset" value=" Reset ">
</fieldset>
<br />
<fieldset><legend>Encoded text</legend>Đoạn text đã được mã hóa:<br />
<textarea cols="35" rows="5" name="ta2" readonly></textarea><br />
<input type=button value="Chọn tất cả" onClick="javascript:this.form.ta2.focus(); this.form.ta2.select();">
<span class="note"><br />
... sau đó click <strong>CTRL+c</strong></span>
</fieldset>
<br>
<fieldset><legend>Text Decoding</legend>Giải mã code:<br />
<textarea cols="35" rows="5" name="ta3"></textarea>
<br>
<input type="button" name="b1" value=" Decode " onclick="decode();">
<input type="reset" value=" Reset ">
</fieldset>
<br>
<span class="note"><a href="javascript:help();">Click for Help! - Trợ giúp</a></span>
</form>
</div>
</body>
</html>
Đánh dấu