/*
CryptoMX Tools
      Copyright (C) 2004 - 2006 Derek Buitenhuis

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation; either version 2
      of the License, or (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
	  
*/	  
	 
var MCarr=new Array(
"*","|",".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",
".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..","-----",".----","..---","...--","....-",
".....","-....","--...","---..","----.",

/* Punc */

". - . - . -","- - . . - -",". . - - . .",". - - - - .","- . - . - -",
"- . . - .","- . - - .","- . - - . -",". - . . .","- - - . . .","- . - . - .","- . . . -",". - . - .","- . . . . -",
". . - - . -",". - . . - .",". . . - . . -",". - - . - .",

/* Other chars */
". - . -",". - . -",
". - - . -",". - - . -",
"- . - . .","- . - . .",
"- - - -",
". . - - .",
". - . . Ð",
". . - . .",". . - . .",
"- - . - .",
"- . - - .",
". - - - .",
"- - . - -",
"- - - .","- - - .",
". . . - .",
". - - . .",
". . - -",". . - -"

);
var ABC012arr="*|ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,?'!/()&:;=+-_\"$@"+String.fromCharCode(228,230,224,229,231,265,353,240,232,233,273,285,293,309,241,246,248,349,254,252,365);	 
	 
function caeserEncrypt(x,shf) {
	abc="abcdefghijklmnopqrstuvwxyz";
	ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	r1="";r2="";shf=eval(shf);
	for(i=0;i<x.length;i++){let=x.charAt(i);pos=ABC.indexOf(let);if(pos>=0){r1+=ABC.charAt(  (pos+shf)%26  )}else{r1+=let};};
	for(i=0;i<r1.length;i++){let=r1.charAt(i);pos=abc.indexOf(let);if(pos>=0){r2+=abc.charAt(  (pos+shf)%26  )}else{r2+=let};};
	return r2;
};

function caeserDecrypt(x,shf) {
	return caeserEncrypt(x,26-shf);
};
function morseDecrypt(x) {
	mess="";apos=0;bpos=0;
	while(bpos<x.length)
	{
	 bpos=x.indexOf(" ",apos);if(bpos<0){bpos=x.length};
	 dits=x.substring(apos,bpos);apos=bpos+1;let="";
	 for(j=0;j<MCarr.length;j++){  if(dits==MCarr[j]){let=ABC012arr.charAt(j)}  };
	 if(let==""){let="*"};
	 mess+=let;
	};
	return mess;
};

function morseEncrypt(x) {
	mess="";
	for(i=0;i<x.length;i++)
	{
	let=x.charAt(i).toUpperCase();
	for(j=0;j<MCarr.length;j++){  if(let==ABC012arr.charAt(j)){mess+=MCarr[j]}  };
	mess+=" ";
	};
	mess=mess.substring(0,mess.length-1);
	return mess;
};