#!/usr/bin/php -q
<?php
/*
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

// This program is a shell script that generates a 104 (128) bit WEP key from an ASCII string

$phrase = @$_SERVER[argv][1];

if (!
$phrase) {
    echo 
"Usage:\n" $_SERVER['PHP_SELF'] . " <passphrase>\n\n";
    exit;
}

$length 64;

// If phrase is too long, trim to 64 characters
$phrase substr($phrase,0,64);

// Repeat the string as many times as necessary and then trim to 64
$phrase substr(str_repeat($phrase, ($length strlen($phrase))), 064);

echo 
"Pass phrase:           "$_SERVER[argv][1] . "\n";
// Use the first 26 digits of the MD5 sum
echo "104 (128) bit WEP Key: " substr(md5($phrase), 026) . "\n";

?>