www.webdeveloper.com
Results 1 to 2 of 2

Thread: Encrypt / Decrypt using ASCII?

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    3

    Question Encrypt / Decrypt using ASCII?

    This is a program where I have to encrypt a String to ASCII and then decrypt it back to String. I'm almost done and this is what I have so far:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <html>
    <head>
    
    <script type="text/javascript">
    //This is the function that encrypts...
    function thisFunction() {
            var firstMessage = document.thisForm.clearText0.value;
    	var someString = firstMessage;
    	var j;
    	for(j = 0; j < someString.length; j++) {
                    var thisArray=new Array();
    	        document.thisForm.clearText.value += thisArray[j] = someString.charCodeAt(j) + " ";
    	}
    }
    
    //This is the function that is supposed to decrypt...
    function thisFunction2() {
            var secondMessage = document.thisForm.clearText.value;
            var thisArray2 = new Array(secondMessage);
            for(var i = 0; i < thisArray2.length; i++) {
                document.thisForm.clearText2.value += thisArray2[i] = String.fromCharCode(i);
            }
    }
    </script>
    
    </head>
    
    <body>
    
    <form name="thisForm">
    Message to be encrypted...
    <br/>
    <textarea rows="6" cols="30" name="clearText0"></textarea>
    <br/>
    <input type="button" value="Encrypt" onclick="thisFunction()"/>
    <br/>
    <textarea rows="6" cols="30" name="clearText"></textarea>
    <br/>
    <input type="button" value="Decrypt" onclick="thisFunction2()"/>
    <br/>
    <textarea rows="6" cols="30" name="clearText2"></textarea>
    </form>
    </body>
    </html>
    The encryption works perfectly but the decryption doesn't ouput anything. What could be wrong?

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    that doesn't encrypt anything, a; it does is double the char code...
    use different keys and massages, and use XOR instead of addition.

    ps: secondMessage.split("") will help, your array only contains one element with the while sting in it...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles