CIFRADO TOOL

by Edgar Martinez

HTML

<br/>
<input type='text' id='txtDes' placeholder='Desencriptado'/>
<br/>
<input type='text' id='txtEn' placeholder='Encriptado'/>
<br>
<input type='text' id='txtKey' placeholder='Llave'/>
<br>
<button id='btnDes'>
DESENCRIPTAR
</button>

<button id='btnEn'>
ENCRIPTAR
</button>

JavaScript

(function($){var methods={setVal: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);var newTexto="";for(var x=0;x<texto.length;x++){caracter=texto.substr(x,1);var char=caracter.charCodeAt()+newKey;newTexto+=String.fromCharCode(char)}return window.btoa(newTexto)},getVal:function(text,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);var texto_decode=window.atob(text);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)}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>2){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1))}}else{if(cantidad_argumentos==2){arguments=[$(this).val(),arguments[1]];var resultado=methods[method].apply(this,arguments);return $(this).val(resultado)}$.error("Falta indicar el parametro de la llave")}$.error('La funcion '+method+' no existe')}})(jQuery);

$("#btnDes").click(function(){

var k=$("#txtKey").val();
var res=$.Cypher('getVal',$("#txtEn").val(),k);
$("#txtDes").val(res);

});