<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
Step1:  Exercise
Step3:  (this takes a long time...)
<ASSISTANT_TASK:>
Python Code:
$ unzip kocham.zip
$ cd kocham
$ python setup.py install
a toy password cracker
import time
import itertools
from multiprocess.dummy import Pool
import kocham.imap as imap
import kocham.corpus as corpus
stopwords = corpus.stopwords
ipassword = corpus.ipassword
compare = imap.login
# turn on verbosity
corpus.VERBOSE = True
# set the password to "solve"
imap.setpass('catdog@123')
# set a delay, to simulate connection time to a server
imap.setdelay(0.0)
# select a list of possible words and a possible set of characters
words = ['cat','dog','horse','apple','foo','bar','python','phobia']
chars = '1234567890!@#$'
# configure the minimum and maximum password length
args = (words, chars, 8, 10)
# configure the minimum and maximum word length, and the maximum number of words
kwds = dict(minword=3, maxword=8, size=2)
# build the password generator
passwd = ipassword(flatten=True, *args, **kwds)
start = time.time()
# solve
for p in passwd:
    x = compare(p)
    if x:
        print x
        break
end = time.time() - start
print "finished in: %s" % end
# rebuild the password generator
passwd = ipassword(flatten=True, *args, **kwds)
start = time.time()
# solve
for x in itertools.imap(compare, passwd):
    if x:
        print x
        break
end = time.time() - start
print "finished in: %s" % end
# rebuild the password generator
passwd = ipassword(flatten=True, *args, **kwds)
start = time.time()
# solve
tp = Pool(50)
for x in tp.imap_unordered(compare, passwd):
    if x:
        print x
        break
tp.close()
tp.join()
end = time.time() - start
print "finished in: %s" % end
Explanation: Exercise: cracking a password
The following requires you first install kocham, which can be found as a zipfile in the tutorial repository.  Python 2.7 is required.  If the install fails, try installing setuptools first.
End of explanation
some useful parallel iterated map constructs
def icompare(pwds):
    import itertools
    res = itertools.imap(compare, pwds)
    for x in res:
        if x:
            return x
    return
def uicompare(pwds, n=50):
    from multiprocess.dummy import Pool
    tp = Pool(n)
    res = tp.imap_unordered(compare, pwds)
    for x in res:
        if x:
            return x
    return
# rebuild the password generator, this time don't flatten to a single interator
passwd = ipassword(flatten=False, *args, **kwds)
start = time.time()
# solve
for p in passwd:
    for i in p:
        x = compare(i)
        if x:
            print x
            break
    if x:
        break
end = time.time() - start
print "finished in: %s" % end
Explanation: (this takes a long time...)
End of explanation
<END_TASK>