最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how can i make a simple wep key generator in javascript? - Stack Overflow

programmeradmin1浏览0评论

im trying to make a wep key generator and ive read how wep keys work but i really dont even know how to start making it. can anyone give me an example or direct me to a tutorial? i tried using google but no luck.

im trying to make a wep key generator and ive read how wep keys work but i really dont even know how to start making it. can anyone give me an example or direct me to a tutorial? i tried using google but no luck.

Share Improve this question asked Mar 22, 2011 at 22:40 nopenope 1,0782 gold badges15 silver badges32 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

in javascript...

function generateHexString(length) {
  // Use crypto.getRandomValues if available
  if (
    typeof crypto !== 'undefined' 
    && typeof crypto.getRandomValues === 'function'
  ) {
    var tmp = new Uint8Array(Math.max((~~length)/2));
    crypto.getRandomValues(tmp);
    return Array.from(tmp)
      .map(n => ('0'+n.toString(16)).substr(-2))
      .join('')
      .substr(0,length);
  }

  // fallback to Math.getRandomValues
  var ret = "";
  while (ret.length < length) {
    ret += Math.random().toString(16).substring(2);
  }
  return ret.substring(0,length);
}

// 40-/64-bit WEP: 10 digit key
alert("40-bit:" + generateHexString(10));

// 104-/128-bit WEP: 26 digit key
alert("104-bit:" + generateHexString(26))

// 256-bit WEP: 58 digit key
alert("256-bit:" + generateHexString(58));

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.

I'm not sure if there is a standard passphrase to WEP generator, but most limit the input to printable characters, and the algorythms are generally weak.. best bet is to simply use WPA2PSK if you can.

发布评论

评论列表(0)

  1. 暂无评论