"""Breaking a CAPTCHA implementation with poor ID encoding (rot13)."""
import urllib, re
PORT = 8002
for i in range(20):
webf = urllib.urlopen('http://localhost:%d' % PORT)
# Look for the CAPTCHA id.
test = re.search('<img src="(.*).jpg"/>', webf.read())
if test != None:
captcha_id = test.groups()[0]
# "Solve" the CAPTCHA by decoding the ID.
solution = captcha_id.encode('rot13')
params = {
'id': captcha_id,
'word': solution
}
webf = urllib.urlopen('http://localhost:%d' % PORT, urllib.urlencode(params))
print i, webf.read(),