Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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.
    Last edited by j0rd4nn; 12-28-2011 at 02:44 AM.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,076
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    I don't know much about PHP, but here is a much simpler version of the encryption/decryption function.
    See: http://jsfromhell.com/string/rot13

    Code:
    <html>
    <head>
    <title> Rot13 Encryption</title>
    <script type="text/javascript">
    //<![CDATA[
    // From: http://jsfromhell.com/string/rot13
    
    String.prototype.rot13 = function(){
        return this.replace(/[a-zA-Z]/g, function(c){
            return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
        });
    };
    
    function codeDcode() {
      var s = document.getElementById('src').value;
      var e = s.rot13();
      document.getElementById('encrypt').value = e;
      document.getElementById('decrypt').value = e.rot13();
    }
    //]]>
    </script>
    </head>
    <body>
    <textarea id="src"></textarea><br>
    <button onclick="codeDcode()">Code &amp; Decode</button><br>
    Encryption<br>
    <textarea id="encrypt"></textarea><br>
    Decryption<br>
    <textarea id="decrypt"></textarea>
    </body>
    </html>

  • Users who have thanked jmrker for this post:

    j0rd4nn (12-28-2011)

  • #3
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I genuinely don't think I could thank you enough. You've saved me big time mate, thanks a lot.

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,076
    Thanks
    38
    Thanked 498 Times in 492 Posts
    You're most welcome.
    Happy to help.
    Good Luck!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •