JavaScript - Rot13 Encrypting
Hey, I've got this script that aparantly encrypts plain text to rot13. Here it is:
Code: <script type="text/javascript"> function rot13(txt) { var map = [] var tmp = "abcdefghijklmnopqrstuvwxyz" var buf = "" for (j = 0; j < tmp.length; j++) { var x = tmp.charAt(j); var y = tmp.charAt((j + 13) % 26) map[x] = y; map[x.toUpperCase()] = y.toUpperCase() } for (j = 0; j < txt.length; j++) { var c = txt.charAt(j) buf += (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' ? map[c] : c) } return buf } </script> <script>var foo = rot13('<?php rec9(); ?>')</script> <script>document.write(foo)</script> I won't lie, my Javascript is terrible. I need to embed that script into a page, and have it encrpyt a PHP variable. I have no idea how because the script is assuming you're loading it externally. Can somebody help reconstruct the script so I can easily parse a PHP variable into it, and then output the result? I really do need help, I've spent quite some time attempting and I've got pretty much nowhere. P.s. PHP Code: <?php rec9(); ?> rec9(); is a function in PHP which retrieves whatever the user posted in the textbox (we can just assume that code really mean "12345") - as you can see, I've attempted to parse it but I just don't know where to start. Hopefully I haven't scrambled it too much so somebody who knows Javascript can't help. I really appreciate any help. Similar TutorialsI have a program with the following code: Code: enc = ":)g8"; for(i=0;i<enc2.length;++i) { document.write(String.fromCharCode(6^enc2.charCodeAt(i))); } The above logic decrypts the value "g8" into "</a>" The manipulation seems to be based on the second character of the hex values, as follows: if the hex value ended in 0, 1, 8, or 9, he added 6; if it ended in 2, 3, A, or B, he subtracted 6; if it ended in 4, 5, C, or D, he subtracted 2; if it ended in 6, 7, E, or F, he subtracted 6. How did it do it??? |