Home
Text Effects
Simple Encoder-Decoder
This is a simple message encoding script. You can encode your message and send it to a friend. He can then decode it using this script. You can also use the script to encrypt your text files. Numbers and special characters are not allowed.
The JavaScript Source: Text Effects: Simple Encoder-Decoder
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Command-s). The script is yours!!!
<!-- THREE STEPS TO INSTALL SIMPLE ENCODER-DECODER:
1. Copy the coding into the HEAD of your HTML document
2. Add the onLoad event handler into the BODY tag
3. Put the last coding into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<style type="text/css">
<!--
.smaller {
font-size: .7em;
}
-->
</style>
<script type="text/javascript">
<!-- Begin
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Kaushal K. Prasad :: http://www.geocities.com/mekaushal/ */
//*** 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) Enter text in the top text area."
m2="2) Press [ Encode ] button to encode it. Encoded text will appear in the middle text area."
m3="3) Copy the encoded text and send/mail it to your friend."
m4="4) He must enter the encoded text in the bottom text area and press [Decode] to see original message."
m5="5) He can use the same method to send/mail any message to you."
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("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","00","##","$$");
/* BE CAREFUL, ADD NEW ITEM OF ONLY TWO CHARACTERS IN THE ARRAY ABOVE
YOU CAN CHANGE THE ITEMS ABOVE ACCORDINGLY YOURSELF,
BUT EACH ITEM SHOULD OF TWO CHARACTERS ONLY */
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"," ",".",",");
//********** 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() {
len=document.f1.ta2.value.length;
document.f1.ta3.value="";
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>
<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->
<BODY onload="javascript:document.f1.ta1.select();">
<!-- STEP THREE: Copy this code into the BODY of your HTML document -->
<div align="center">
<form name="f1">
Enter the text to be encoded below<br>
<span class="smaller">(Numbers and special characters not allowed )</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 ">
<br><br>
Encoded text is below<br>
<textarea cols="35" rows="5" name="ta2" readonly></textarea><br>
<input type=button value="Highlight All" onClick="javascript:this.form.ta2.focus();this.form.ta2.select();"> <span class="smaller">... then click CTRL+c</span>
<br><br>
Enter the text to be decoded below<br>
<textarea cols="35" rows="5" name="ta3"></textarea><br>
<input type="button" name="b1" value=" Decode " onclick="decode();"> <input type="reset" value=" Reset ">
<br><br>
<span class="smaller"><a href="http://www.geocities.com/mekaushal/">Kaushal K. Prasad</a> :: <a href="javascript:help();">Click for Help!</a></span>
</form>
</div>
<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 4.21 KB --> Did you use this script? Do you like this site? Please link to us!
Comments feed