/*

Title:	WLAN Strong Key Generator (wlanSKG) version 2.2

		(formerly WEP Strong Key Generator)

Author: Chris Elliott
		Warewolf Labs
		www.warewolflabs.com

Release Notes:

=== 	version 2.2.MSL

Date:	2005-04-27

Info:	1. A few minor usability changes, no substantial changes to workings	


=== 	version 2.2

Date:	2005-01-25

Info:	1. Contains minor updates to the instructions in preparation for a full rewrite and
		increase in functionality of this script (i.e. WPA-PSK generation, etc.), slated
		for a later release (2.3+).	


====	version 2.1


Version: 2.1		
Date:	2002-12-14

Info:	A JavaScript program written to enable Wireless LAN (WLAN) administrators 
        to quickly create strong keys for implementing Wired Equivalent Privacy 
        (WEP) as a first line of defense in strengthening the security of their 
        wireless networks. Keys can be selectively generated for use with 64-, 
        128-, 152-, and 256-bit WEP key lengths.  Additionally, user-defined pass
		phrases can be converted to Hex format for use as WEP keys (more info below).

	    It has been freely released to the public as part of an effort to increase 
        awareness of WLAN security issues, and to increase the baseline security 
        of current and future installations.
		
		While this file may be freely distributed, the copyright has been retained
		for all code generated by Chris Elliott / Warewolf Labs, and this information 
        must remain intact (i.e. don't pretend that you or your company wrote this, or
        offer it to your clients without giving due credit).
		
		The addition of the custom passphrase code in version 2.1 was based on a 
		suggestion/initial implementation by Kraix (www.kraix.com); additionally, Kraix 
		supplied some needed refinements to the instructions included for this program.  
		Much thanks is in order for those things, as they provided the impetus to update 
		this script from its original release in order to support 256-bit WEP keys along 
		with some other touch-ups.

*/

// initialize WEP key variables

var ascWEPkey = '';
var hexWEPkey = '';

// creates an array of 95 possible characters from which to choose for generating our WEP key
var charArray = new Array(' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '\'', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~');

// functions

function gen_prn() {					// generates a pseudo-random number

	return Math.floor(Math.random() * charArray.length); // range is 0 ~ 94
}

function gen_key(keyLengthInBytes) {	// generate a WEP key with the specified key length in bytes (5/13/16/29 bytes for 64/128/152/256-bit WEP)
	
	for (i = 0; i < keyLengthInBytes; i++)
	{
		ascWEPkey += charArray[gen_prn()];  // creates the ASCII version of the WEP key
	}

	for (i = 0; i < ascWEPkey.length; i++)
	{
    	hexWEPkey += ascWEPkey.charCodeAt(i).toString(16);   // creates the HEX WEP key from the ASCII 
	}
}

function write_key(tf) {	// write the WEP key into the form text fields
    tf.ascKeyTextField.value = ascWEPkey;
    tf.hexKeyTextField.value = hexWEPkey;
    tf.customPhraseField.value = ascWEPkey;
    write_cc(tf);
}

function write_cc(tf) {		// Write the key length
	tf.customPhraseCCField.value = tf.customPhraseField.value.length;
}
function reset_key() {		// reset the WEP key variables for further use
	ascWEPkey = '';
	hexWEPkey = '';
}

function go(form, klib) {	// trigger function to generate a key, display the output, and then reset the variables

	gen_key(klib);
	write_key(form);
	reset_key();
}

function go_ck(form) {		// trigger function to generate a custom key from a user-supplied pass phrase
							// checking for proper key lengths is left up to the user
							
	if ( form.customPhraseField.value != '') // did they actually enter anything?
	{
		ascWEPkey = form.customPhraseField.value;
		for (i = 0; i < ascWEPkey.length; i++)
			hexWEPkey += ascWEPkey.charCodeAt(i).toString(16);   // creates the HEX WEP key from the ASCII
	}
	else
	{
		alert("Please enter a pass phrase.");
	}
	write_key(form);
	reset_key();
}


/*
Highlight and Copy form element script- By Dynamicdrive.com
For full source, Terms of service, and 100s DTHML scripts
Visit http://www.dynamicdrive.com
*/

//specify whether contents should be auto copied to clipboard (memory)
//Applies only to IE 4+
var copytoclip=1

function HighlightAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
if (document.all&&copytoclip==1){
therange=tempval.createTextRange()
therange.execCommand("Copy")
window.status="Contents highlighted and copied to clipboard!"
setTimeout("window.status=''",1800)
}
}

