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 ファイルの何が問題なのですか?「\」バックスラッシュですか? 文字列の例を1つ入れると機能します

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

結果は次のとおりです: \x51

ヘルプやデバッグに感謝します

前もって感謝します

4

3 に答える 3

2

スラッシュをエスケープする必要はありません。「\x51」で十分です。

于 2012-06-26T08:04:51.753 に答える
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 に答える
1

mここで複数行パターン修飾子が欠落していると思います:

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