How to generate "unescape" within code

Asked

Viewed 295 times

-3

I have a simple unescape encryptor and would like the generated NCO to be within the default code of unescape, like:

code 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, he wanted the generated code to appear along with the code below:

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

by the time you generate the code all comes out and not only Ncode without script...

  • is only html code

  • Okay, and what exactly do you want to happen that actually doesn’t happen? and how hard are you having to do what you want? These things already have to be part of the question, otherwise it gets complicated. Note that it is not unwillingness to help, but is that if every question the staff has to keep trying to understand the problem, disturbs the side of those who help and yours. It is suggested to read in [Ask], and then [Edit] the question as clearly as possible.

  • when generating the code, generate inside the script, ready to copy after generating because if not I have to take the generated code and put manually inside the script <script language='javascript'> Document.write( unescape( 'generated code would be here' ) ); </script>

  • In this case it is not only include the code when giving the escape?

  • not include the code it will be hidden...

  • exact, and will be "undone" Ué.

  • you did not understand, type vo encodar any type of html and use them encodata in javascript unescape, if I put the javascript code at encodar time will encodar everything and I would have to put the javascript code the same way understood, i just want it to be generated with javascript...

  • You don’t have to put it inside the meeting, right... you concatenate after it’s coded. Actually I think it’s cool that you’re doing it as an exercise, because it’s no use, but then you have to see where you invest the time. However, it would be enough to put the code inside the function Encode, as string, before the return.

  • I use this type of code from 2009 until today use, so if you can’t or can’t help me, don’t say I won’t need the code, because if I’m asking the question on the site is why I need to.

  • 1

    Well, I’m warning you and I’m wasting my time here to help you, I’ve practically said the solution, but if you’re so sure that I’m wrong, I’ll take care of something else then. Anyway, good luck and good night.

  • "just put the code inside the function Ncode, as string, before the return" seems simple for those who understand... if I knew how to do would not be here né kkkk, but good night msm so and sorry for making you waste your precious time...

  • It was just an orientation of how to do, maybe later someone gives an example in an official answer. As for the fact that the code does not have much use is that in practice anyone decodes the data with ease, so it does not compensate for the time you spend with this type of thing, and still ends up hindering the indexing of the content. But the code is yours, you have every right to do as you wish, I just think it’s important that you know.

  • Ta good, everyone has their opinion right, and as you said ta spending your time here atoa, do not want to argue with anyone and not even know if it is good or bad the code, just want the solution to my question if possible.

Show 8 more comments

1 answer

0


I’ve done it, even though it’s not the same code but it’s good enough for me:

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 comes out with javascript, vlw to everyone who could not help me and voted negative :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.