//debe tener lib jquery.cookie //retorna la longitud de bits maxima permitda junto con el codigo ascii function strpad_char(c){ var d=""; var n=ord(c); var sn=new String(n); var l=sn.length; for(u=l;u<5;u++){ d += "0"; } return d+n } //retorna el codigo de caracter function ord (string) { var str = string + '', code = str.charCodeAt(0); if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters) var hi = code; if (str.length === 1) { return code; // This is just a high surrogate with no following low surrogate, so we return its value; // we could also throw an error as it is not a complete character, but someone may want to know } var low = str.charCodeAt(1); return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000; } if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate return code; // This is just a low surrogate with no preceding high surrogate, so we return its value; // we could also throw an error as it is not a complete character, but someone may want to know } return code; } //retorna uid mod function loopmod(ciclo,factor,entrada){ var r=entrada; for(m=2;m<=ciclo;m++){ r=(entrada*r)%factor; } return r; } //codificar function ecs(s){ var ps=new String(s); var ls=ps.length; var output=new String(""); var input=new String(""); var factor=$.cookie("factor"); var ciclo=$.cookie("ciclo"); for(a=0;a<=ls;a++){ var posactstr=ps.substr((a-1),a); if(posactstr.length>0){ output+=loopmod(ciclo,factor,ord(posactstr))+" ";//para version 1 //output+=loopmod(ciclo,factor,bin2hex(ord(posactstr)))+" ";//para version 2 } } return Base64.encode(output); } //decodificar function decs(valor){ var factor=$.cookie("factor"); var ciclo=$.cookie("ciclo"); return loopmod(ciclo,factor,valor); } function bin2hex (s) { var i, f = 0, a = []; s += ''; f = s.length; for (i = 0; i < f; i++) { a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/, "0$1"); } return a.join(''); } function hex2bin(hex) { var bytes = [], str; for(var i=0; i< hex.length-1; i+=2){ bytes.push(parseInt(hex.substr(i, 2), 16)); } return String.fromCharCode.apply(String, bytes); }