Cypher JQuery Plugin

Plugin para encriptar y desencriptar texto

by Edgar Martinez

HTML

<input type='text' id="texto" value="edgar" />
<br>
<hr>
<button id="btnEncriptar">Encriptar</button><button id="btnDesencriptar">Desencriptar</button>

JavaScript

$("#btnEncriptar").click(function(){
 $("#texto").Cypher('encriptar',"PalosGarza");
 /*
 
 var textoDemo=$.Cypher("encriptar","mi cadena","miLlave")
 console.log(textoDemo); 
  $("#texto").Cypher('encriptar',"texto","llave");
 */
});
$("#btnDesencriptar").click(function(){
 $("#texto").Cypher('desencriptar',"PalosGarza");
});


;(function($){

	var methods = {
		encriptar : function( texto,llave ) { 
	
 
      var key=0;
      for(var k=0;k<llave.length;k++){
               keychar = llave.substr(k,1);
               key=key+Number(keychar.charCodeAt());
              
      }
      var newKey=parseInt(parseInt(key/llave.length)/llave.length);
      
       console.log(newKey);
      var newTexto="";
      for(var x=0; x<texto.length;x++){
       caracter=texto.substr(x,1);
       var char=caracter.charCodeAt()+newKey;
       newTexto+=String.fromCharCode(char);
        
      // textoFinal
      }
    
      
     return window.btoa(newTexto);
		},
		desencriptar : function( text,llave ) {
		  //codigo
      var key=0;
      for(var k=0;k<llave.length;k++){
               keychar = llave.substr(k,1);
               key=key+Number(keychar.charCodeAt());
              
      }
      var newKey=parseInt(parseInt(key/llave.length)/llave.length);//obtenemos la llave principal
       console.log(newKey);
      
      var texto_decode=window.atob(text);//decodificamos el base 64
      var newTexto="";
      for(var x=0; x<texto_decode.length;x++){
       caracter=texto_decode.substr(x,1);
       var char=caracter.charCodeAt()-newKey;
       newTexto+=String.fromCharCode(char);
       
      // textoFinal
      }
       
     return newTexto;
		}
  };
$.Cypher=function(method){
 if ( methods[method]) {
                    return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
                }

};
$.fn.Cypher=function(method){
       

            var cantidad_argumentos=arguments.length;
          
            if(cantidad_argumentos >...