Hex String Generator


/ Published in: JavaScript
Save to your folder(s)

If you wanted to generate something based on a fixed string input, there are methods for doing that as well... this should give you what you are looking for in terms of just a straight random hex string of the correct length.


Copy this code and paste it in your HTML
  1. function generateHexString(length) {
  2. var ret = "";
  3. while (ret.length < length) {
  4. ret += Math.random().toString(16).substring(2);
  5. }
  6. return ret.substring(0,length);
  7. }
  8.  
  9. // 40-/64-bit WEP: 10 digit key
  10. alert("40-bit:" + generateHexString(10));
  11.  
  12. // 104-/128-bit WEP: 26 digit key
  13. alert("104-bit:" + generateHexString(26))
  14.  
  15. // 256-bit WEP: 58 digit key
  16. alert("256-bit:" + generateHexString(58));

URL: http://stackoverflow.com/questions/5398737/how-can-i-make-a-simple-wep-key-generator-in-javascript

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.