0

我想制作一个简单的生成器.. 使用 replace() 方法。好吧,我的问题是替换值

    <html>
     <head>
            <meta content="Wordpress V. 3.3.2" name="Generator">
            <meta content="MemoGeek, WGCracker, MG, MemoryGeek, Mu\'min Azad" name="Programmer">
            <meta content="I'm A Developer, Programmer, Photographer, Nerd, Geek, Cracker, Designer, Feel Free To Request" name="About">
            <meta content="MemoGeek, WGCracker, MG, MemoryGeek, Mu\'min Azad" name="Designer">
            <meta content="Http://YouTube.com/WindowsGhostCracker" name="YouTube Channel">
            <meta content="Http://Facebook.com/WGCracker" name="Facebook">
            <meta content="Http://Twitter.com/WGCracker" name="Twitter">
            <meta content="Http://Gplus.to/WGCracker" name="Google Plus">
            <meta content="Http://Gplus.to/WGCracker" name="Google Plus">
            <title>Garbled Javascript Encoder / Decoder</title>
            <link rel="stylesheet" href="jquery-ui.css"> 
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" ></script>
            <script src="jquery-ui-1.8.16-custom.js" ></script>
   </head> 

</div></div>
<div id="home-header"><!-- blank --></div>
<div id="home-page"><!-- blank --></div>
<div id="home-main"><!-- blank --></div>
<div id="home-content">
<div id="crosscol-wrapper" style="display:none;">
<div class="crosscol section" id="crosscol"></div>
</div>
<div id="home-blog-info">
<div class="header section" id="header"><div class="widget Header" id="Header1">
<div id="header-inner">
<div class="titlewrapper">
<h1 class="title">Developer<font color="#0CBAB0"></font>
<font color="#7AEEDD">G</font>
<font color="#924463">a</font>
<font color="#EBB070">r</font>
<font color="#9A0C59">l</font>
<font color="#74DF7E">e</font>
<font color="#2DB2E0">d</font>
<font color="#077EDD"> </font>
<font color="#0BD91C">J</font>
<font color="#ffffff">a</font>
<font color="#7A7BC3">v</font>
<font color="#0E306E">a</font>
<font color="#75709A">S</font>
<font color="#435854">c</font>
<font color="#52CACB">r</font>
<font color="#CE7BE9">i</font>
<font color="#61C47D">p</font> 
<font color="#924463">t</font>
Generator
</h1>
</div>
<div class="descriptionwrapper">
<p class="description"><span>
</span></p>
</div>
</div>
</div></div>
<div class="home-descriptionsec section" id="home-descriptionsec"><div class="widget HTML" id="HTML1">
<div class="widget-content">
<div style="overflow: hidden; width: 10px; height: 12px; position: absolute; filter:alpha(opacity=0); -moz-opacity:0.0; -

khtml-opacity: 0.0; opacity: 0.0;" id="icontainer">




</div>
<div>
<script language="JavaScript" type="text/javascript">
var thisString;
function startText() {
thisString = document.myjsg.box1.value;
thisString = thisString.replace(/A/g, "\\x41");
thisString = thisString.replace(/B/g, "\\x42");
thisString = thisString.replace(/C/g, "\\x43");
thisString = thisString.replace(/D/g, "\\x44");
thisString = thisString.replace(/E/g, "\\x45");
thisString = thisString.replace(/F/g, "\\x46");
thisString = thisString.replace(/G/g, "\\x47");
thisString = thisString.replace(/H/g, "\\x48");
thisString = thisString.replace(/I/g, "\\x49");
thisString = thisString.replace(/J/g, "\\x4a");
thisString = thisString.replace(/K/g, "\\x4b");
thisString = thisString.replace(/L/g, "\\x4c");
thisString = thisString.replace(/M/g, "\\x4d");
thisString = thisString.replace(/N/g, "\\x4e");
thisString = thisString.replace(/O/g, "\\x4f");
thisString = thisString.replace(/P/g, "\\x50");
thisString = thisString.replace(/Q/g, "\\x51");
thisString = thisString.replace(/R/g, "\\x52");
thisString = thisString.replace(/S/g, "\\x53");
thisString = thisString.replace(/T/g, "\\x54");
thisString = thisString.replace(/U/g, "\\x55");
thisString = thisString.replace(/V/g, "\\x56");
thisString = thisString.replace(/W/g, "\\x57");
thisString = thisString.replace(/X/g, "\\x58");
thisString = thisString.replace(/Y/g, "\\x59");
thisString = thisString.replace(/Z/g, "\\x5a");
/* 
Start Of Small Letters
*/
thisString = thisString.replace(/a/g, "\\x61");
thisString = thisString.replace(/b/g, "\\x62");
thisString = thisString.replace(/c/g, "\\x63");
thisString = thisString.replace(/d/g, "\\x64");
thisString = thisString.replace(/e/g, "\\x65");
thisString = thisString.replace(/f/g, "\\x66");
thisString = thisString.replace(/g/g, "\\x67");
thisString = thisString.replace(/h/g, "\\x68");
thisString = thisString.replace(/i/g, "\\x69");
thisString = thisString.replace(/j/g, "\\x6a");
thisString = thisString.replace(/k/g, "\\x6b");
thisString = thisString.replace(/l/g, "\\x6c");
thisString = thisString.replace(/m/g, "\\x6d");
thisString = thisString.replace(/n/g, "\\x6e");
thisString = thisString.replace(/o/g, "\\x6f");
thisString = thisString.replace(/p/g, "\\x70");
thisString = thisString.replace(/q/g, "\\x71");
thisString = thisString.replace(/r/g, "\\x72");
thisString = thisString.replace(/s/g, "\\x73");
thisString = thisString.replace(/t/g, "\\x74");
thisString = thisString.replace(/u/g, "\\x75");
thisString = thisString.replace(/v/g, "\\x76");
thisString = thisString.replace(/w/g, "\\x77");
thisString = thisString.replace(/x/g, "\\x78");
thisString = thisString.replace(/y/g, "\\x79");
thisString = thisString.replace(/z/g, "\\x7a");
/*
Numbers
*/
thisString = thisString.replace(/0/g, "\\x30");
thisString = thisString.replace(/1/g, "\\x31");
thisString = thisString.replace(/2/g, "\\x32");
thisString = thisString.replace(/3/g, "\\x33");
thisString = thisString.replace(/4/g, "\\x34");
thisString = thisString.replace(/5/g, "\\x35");
thisString = thisString.replace(/6/g, "\\x36");
thisString = thisString.replace(/7/g, "\\x37");
thisString = thisString.replace(/8/g, "\\x38");
thisString = thisString.replace(/9/g, "\\x39");
/*
Unicodes, Tags And More
*/
thisString = thisString.replace(/\@/g, "\\x40");
thisString = thisString.replace(/\`/g, "\\x60");
thisString = thisString.replace(/\!/g, "\\x21");
thisString = thisString.replace(/\"/g, "\\x22");
thisString = thisString.replace(/\#/g, "\\x23");
thisString = thisString.replace(/\$/g, "\\x24");
thisString = thisString.replace(/\%/g, "\\x25");
thisString = thisString.replace(/\&/g, "\\x26");
thisString = thisString.replace(/\"/g, "\\x27");
thisString = thisString.replace(/\(/g, "\\x28");
thisString = thisString.replace(/\)/g, "\\x29");
document.myjsg.box2.value=thisString;
}

</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function combine(form) {
form.field3.value = form.box2.value + form.subject.value;
}
//-->
</script>
<form id="myjsg" name="myjsg">
<textarea name="box1" cols="40"></textarea>
<input type="hidden" name="subject" id="subject" value="">                             

   <br>

<input onClick="startText();combine(this.form);" type="button" value="    Encode    "> 
  <br>
                     <input name="box2" size="70" type="hidden" value="">
  <textarea name="field3" cols="40"></textarea>
</form>
</div>

</body>
</html>

和 jquery-ui-1.8.16-custom:

(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '//pagead2.googlesyndication.com/pagead/js/google_top.js';
var head = document.getElementsByTagName('head')[0];
if (head) {
head.appendChild(script);
}})();

这个html文件有什么问题是“\”反斜杠吗?当我放一个字符串示例时它的工作原理

thisString = thisString.replace(/Q/g, "\\x51");

结果是:\x51

我感谢任何帮助或调试

提前致谢

4

3 回答 3

2

只是一个注释——大量重复的代码可以用一个基于String.prototype.charCodeAt的简单函数代替:

function replaceWithCode(s) {
  var t = '';
  for (var i=0, iLen=s.length; i<iLen; i++) {
    t +='\\x' + s.charCodeAt(i).toString(16);
  }
  return t;
}

replaceWithCode('A9$'); // \x41\x39\x24
于 2012-06-26T08:42:53.583 回答
2

你不需要逃避斜线;"\x51" 就足够了。

于 2012-06-26T08:04:51.753 回答
1

我猜您在m这里缺少多行模式修饰符:

thisString = thisString.replace(/Q/mg, "\\x51");
于 2012-06-26T08:05:21.690 回答