j0rd4nn
12-28-2011, 02:40 AM
Hey, I've got this script that aparantly encrypts plain text to rot13. Here it is:
<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. :thumbsup:
P.s. <?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.
<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. :thumbsup:
P.s. <?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.