• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Text Effects / Simple Encoder-Decoder

Simple Encoder-Decoder

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.

Enter the text to be encoded below
(Numbers and special characters not allowed )

    

Encoded text is below

… then click CTRL+c

Enter the text to be decoded below

    

Kaushal K. Prasad  ::  Click for Help!
  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
<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://javascriptsource.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 __________nn”;
  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>
<BODY onload="javascript:document.f1.ta1.select();">
<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” class=”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=”https://javascriptsource.com”>The JavaScript Source</a></font>
</center><p>

Text Effects

Related Snippets:

  • Dynamically changing the text color based on background color contrast
  • Get the text content of an element
  • Transform all text in a string to uppercase
  • Reverse Text Wizard

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers