def break_simplesub(ctext, startkey=None):
 ctext = re.sub('[^A-Z]', '', ctext.upper())
 (parentkey, parentscore) = ((startkey or list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')), (-9.9e+100))
 if (not startkey):
  random.shuffle(parentkey)
 parentscore = fitness.score(sub_decipher(ctext, parentkey))
 count = 0
 while (count < 1000):
  a = random.randint(0, 25)
  b = random.randint(0, 25)
  child = parentkey[:]
  (child[a], child[b]) = (child[b], child[a])
  score = fitness.score(sub_decipher(ctext, child))
  if (score > parentscore):
   (parentscore, parentkey) = (score, child[:])
   count = 0
  count += 1
 return (parentscore, parentkey)

def break_simplesub ( ctext , startkey = None ) : ctext = re . sub ( '[^A-Z]' , '' , ctext . upper ( ) ) ( parentkey , parentscore ) = ( ( startkey or list ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) ) , ( - 9.9e+100 ) ) if ( not startkey ) : random . shuffle ( parentkey ) parentscore = fitness . score ( sub_decipher ( ctext , parentkey ) ) count = 0 while ( count < 1000 ) : a = random . randint ( 0 , 25 ) b = random . randint ( 0 , 25 ) child = parentkey [ : ] ( child [ a ] , child [ b ] ) = ( child [ b ] , child [ a ] ) score = fitness . score ( sub_decipher ( ctext , child ) ) if ( score > parentscore ) : ( parentscore , parentkey ) = ( score , child [ : ] ) count = 0 count += 1 return ( parentscore , parentkey )
perform hill-climbing with a single start .