def metasploit_pattern(sets=None):
 sets = (sets or [string.ascii_uppercase, string.ascii_lowercase, string.digits])
 offsets = ([0] * len(sets))
 offsets_indexes_reversed = list(reversed(range(len(offsets))))
 while True:
  for (i, j) in zip(sets, offsets):
   (yield i[j])
  for i in offsets_indexes_reversed:
   offsets[i] = ((offsets[i] + 1) % len(sets[i]))
   if (offsets[i] != 0):
    break
  if (offsets == ([0] * len(sets))):
   return

def metasploit_pattern ( sets = None ) : sets = ( sets or [ string . ascii_uppercase , string . ascii_lowercase , string . digits ] ) offsets = ( [ 0 ] * len ( sets ) ) offsets_indexes_reversed = list ( reversed ( range ( len ( offsets ) ) ) ) while True : for ( i , j ) in zip ( sets , offsets ) : ( yield i [ j ] ) for i in offsets_indexes_reversed : offsets [ i ] = ( ( offsets [ i ] + 1 ) % len ( sets [ i ] ) ) if ( offsets [ i ] != 0 ) : break if ( offsets == ( [ 0 ] * len ( sets ) ) ) : return
metasploit_pattern -> generator generator for a sequence of characters as per metasploit frameworks rex::text .