#!/usr/bin/python # Accepts a passphrase on the command line and converts it to a WEP key. # The algorithm extends the passphrase to 64 characters and runs it # through md5sum. The result is the WEP key. # # Resources for this most simple of algorithms are difficult to find on the # Internet because so many people want to sell a program to do it. import md5 import sys def usage(): print "usage: %s PHRASE" % sys.argv[0] print " Enclose PHRASE in quotes if it includes whitespace or shell meta-chars." print " PHRASE was '%s'" % phrase sys.exit(1) if len(sys.argv) < 2 or not sys.argv[1]: usage() def makekey(phrase,size=104): if len(phrase) > 64: phrase = phrase[:64] m = md5.new() c = 64 while c >= len(phrase): m.update(phrase) c -= len(phrase) if c: m.update(phrase[:c]) return m.hexdigest()[:size/4] phrase = sys.argv[1] size = 40 print ' passphrase: "%s"' % phrase print "%d bit WEP key: %s\n" % (size,makekey(phrase,size))