How to generate "unescape" inside code

-3

I have a simple unescape encryption and would like the generated encode to stay within the default unescape code, type:

code that I use:

var encN=1;

  function decodeTxt(s){
  var s1=unescape(s.substr(0,s.length-1));
  var t='';
  for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1));
  return unescape(t);
        }

  function encodeTxt(s){
  s=escape(s);
  var ta=new Array();
  for(i=0;i<s.length;i++)ta[i]=s.charCodeAt(i)+encN;
  return ""+escape(eval("String.fromCharCode("+ta+")"))+encN;
  }

  function escapeTxt(os){
  var ns='';
  var t;
  var chr='';
  var cc='';
  var tn='';
  for(i=0;i<256;i++){
  tn=i.toString(16);
  if(tn.length<2)tn="0"+tn;
  cc+=tn;
  chr+=unescape('%'+tn);
  }
  cc=cc.toUpperCase();
  os.replace(String.fromCharCode(13)+'',"%13");
  for(q=0;q<os.length;q++){
  t=os.substr(q,1);
  for(i=0;i<chr.length;i++){
  if(t==chr.substr(i,1)){
  t=t.replace(chr.substr(i,1),"%"+cc.substr(i*2,2));
  i=chr.length;
  }}
  ns+=t;
  }
  return ns;
  }
  function unescapeTxt(s){
  return unescape(s);
  }
  function wF(s){
  document.write(decodeTxt(s));
  }

html:

<div id="wrap">
        <form name="fA">
<div id="casa">
          <input type="button" value="Encode" onclick="document.fA.c1.value=escapeTxt(document.fA.f1.value)"> &nbsp; &nbsp;
                    <br/>

          <textarea id="f1" cols=50 rows=10 wrap="off"></textarea>

</div>
<div id="casa2">
          <input type="button" value="Decode" onclick="document.fA.f1.value=unescapeTxt(document.fA.c1.value)">
          <br>
          <textarea id="c1" cols=50 rows=10></textarea>

</div>
        </form>
</div>

However, I wanted the generated code to appear along with the code below:

<script language='javascript'>
document.write( unescape( 'CODIGO GERADO AQUI' ) );
</script>

When I generate the code, everything comes out and not only the encode without script ...

    
asked by anonymous 12.04.2016 / 04:04

1 answer

0

I have already achieved, although it is not the same code but for me it is already good:

var encN=1;

// ENCODES, IN UNICODE FORMAT, ALL TEXT AND THEN ESCAPES THE OUTPUT
function encodeTxt(s){
s=escape(s);
var ta=new Array();
for(i=0;i<s.length;i++)ta[i]=s.charCodeAt(i)+encN;
return ""+escape(eval("String.fromCharCode("+ta+")"))+encN;
}


// WRITES THE DECODED OUTPUT, ALONG WITH THE ESCAPED DECODER FUNCTION TO THE DIV
function writeOut(){
document.forms["fa"].output.value="<"+"script language='javascript'"+">document.write(unescape('%3C%73%63%72%69%70%74%20%6C%61%6E%67%75%61%67%65%3D%22%6A%61%76%61%73%63%72%69%70%74%22%3E%66%75%6E%63%74%69%6F%6E%20%64%46%28%73%29%7B%76%61%72%20%73%31%3D%75%6E%65%73%63%61%70%65%28%73%2E%73%75%62%73%74%72%28%30%2C%73%2E%6C%65%6E%67%74%68%2D%31%29%29%3B%20%76%61%72%20%74%3D%27%27%3B%66%6F%72%28%69%3D%30%3B%69%3C%73%31%2E%6C%65%6E%67%74%68%3B%69%2B%2B%29%74%2B%3D%53%74%72%69%6E%67%2E%66%72%6F%6D%43%68%61%72%43%6F%64%65%28%73%31%2E%63%68%61%72%43%6F%64%65%41%74%28%69%29%2D%73%2E%73%75%62%73%74%72%28%73%2E%6C%65%6E%67%74%68%2D%31%2C%31%29%29%3B%64%6F%63%75%6D%65%6E%74%2E%77%72%69%74%65%28%75%6E%65%73%63%61%70%65%28%74%29%29%3B%7D%3C%2F%73%63%72%69%70%74%3E'));dF('"+encodeTxt(document.forms['fa'].f2.value)+"')<"+"/script>";
}

html:

<form name="fa">

   <textarea id="f2" cols="80" rows="15" wrap="off" class="code">
<SCRIPT LANGUAGE="javascript">
// SAMPLE SCRIPT #1
alert('Hello World');
</SCRIPT>

<SCRIPT LANGUAGE="javascript" SRC="your_js_file.js">
// SAMPLE SCRIPT #2 - CALLING AN EXTERNAL JS FILE
</SCRIPT>
   </textarea>

   <br />
   <select name="et" onchange="encN=this.selectedIndex+1" class="inpS">
    <option selected>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
   </select>

   <input type="button" class="inpB" value="Encode" onclick="writeOut()" /> 
   <input type="reset" class="inpB" value="Limpar" />
  <br />
   <textarea name="output" class="code" id="caixe" rows="15" cols="80">
Encoded output will be displayed here...
   </textarea>
</form>

The generated code already leaves with the javascript, vlw to all who did not know to help me and voted negative:)

    
12.04.2016 / 17:07