942,782 Members | Top Members by Rank

Ad:
Jun 30th, 2010
-1

How to simple encoding decoding

Expand Post »
The task is very simple; you have to work on two functions Encrypt and Decrypt. The encrypt function will encrypt the user input string with the help of encryption key. The decrypt function will decrypt the user input string with the help of encryption key. The output will






Hints:

Encoding:
Read each character of user input and find its ASCII code using function charCodeAt. Add the key value into ASCII code of each character and covert new ASCII code to character by using function fromCharCode. Display all characters into Encoded Output box.

For example, you entered a character ‘X’, which has ASCII value 130. Add key value in 130, for example, 130+16=146. Then convert 146 to respective Character.

Decoding:
Read each character of user input and find its ASCII code using function charCodeAt. Subtract the key value from ASCII code of each character and covert new ASCII code to character by using function fromCharCode. Display all characters into Original String box.




please solve my assignement i am waiting
Similar Threads
Reputation Points: 8
Solved Threads: 1
Light Poster
gazzy1 is offline Offline
35 posts
since Jun 2010
Jun 30th, 2010
0
Re: How to simple encoding decoding
Click to Expand / Collapse  Quote originally posted by gazzy1 ...
please solve my assignement i am waiting
We're not here to do your assignments. We will help you if you run into trouble. When you get stuck, post your code and/or errors here with an explanation.
Sponsor
Featured Poster
Reputation Points: 546
Solved Threads: 715
Bite my shiny metal ass!
pritaeas is offline Offline
4,137 posts
since Jul 2006
Jun 30th, 2010
-1
Re: How to simple encoding decoding
Sample:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4. <title> New Document </title>
  5. <meta name="Generator" content="EditPlus">
  6. <meta name="Author" content="">
  7. <meta name="Keywords" content="">
  8. <meta name="Description" content="">
  9. </head>
  10.  
  11. <body>
  12. <script language="javascript">
  13. String.prototype.toEncodedString = function(){var ostr=this.toString().replace(/\s+/g,'');if(ostr.length<8){alert("Password must be at least 8 characters long with no spaces.");return null;};var x,nstr='',len=ostr.length;for(x=0;x<len;++x){nstr+=(255-ostr.charCodeAt(x)).toString(36).toUpperCase().toPaddedString(2,'0');};return nstr;};
  14. String.prototype.fromEncodedString = function(){var ostr=this.toString();var x,nstr='',len=ostr.length;for(x=0;x<len;x+=2){nstr+=String.fromCharCode(255-parseInt(ostr.substr(x,2),36));};return nstr;};
  15. Number.prototype.toPaddedString = function(len,pad){len=(len)?Number(len):2;if(isNaN(len)){alert("Padded String 'length' argument is not numeric.");return null;};var dflt=(isNaN(this.toString()))?" ":"0";pad=(pad)?pad.toString().substr(0,1):dflt;var str=this.toString();if(dflt=="0"){while(str.length<len)str=pad+str;};else{while(str.length<len)str+=pad;};return str;};
  16. String.prototype.toPaddedString = Number.prototype.toPaddedString;
  17. //
  18. var str = window.prompt('Enter string to encode:','');
  19. if (str = str.toEncodedString())
  20. {
  21. str = window.prompt('Enter encoded string:',str);
  22. str = str.fromEncodedString();
  23. alert(str);
  24. }
  25. else
  26. {
  27. alert('Encoding cancelled.');
  28. }
  29. </script>
  30. </body>
  31. </html>
Reputation Points: 167
Solved Threads: 239
Nearly a Posting Virtuoso
rajarajan07 is offline Offline
1,445 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: image button not posting
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: presentation witout load bar





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC