Is it proper to use nested loops a lot in python? I have a project and I am trying to do a complex cryptographic method. Is it normal to use nested loops a lot? Or Did I miss something?

I intend to create a method which tries all strings to find password. For example, It should create each of these one by one: ('A','A') ('B', 'A') ('A', 'B') ('B', 'B') ('A', 'AA' ) ('A', 'AB') ('B', 'AA') ('B', 'AB') ('A', 'BA') ('B', 'BA') ('A', 'BB') ('B', 'BB') , (triple permutations), (quadruple permutations).. and it goes...

def rulefinder():
    global externalrul1
    global externalrul2
    rul2 = uniquestring1[0]
    rul1 = uniquestring1[0]
    for n in range (0,3):
     for m in range (0, len(uniquestring1)):
      for z in range(0, n+1):
        for k in range (0,3):
            for i in range(0, len(uniquestring1)):
                for o in range(0, k+1):
                    for y in range (0,  len(uniquestring1)):
                        rul2 = rul2[:-1] + uniquestring1[y]
                        for x in range (0, len(uniquestring1)):
                            rul1= rul1[:-1] + uniquestring1[x]
                            code=""
                            for cha in Genx1:
                                if cha==uniquestring1[0]:
                                    code +=codereplacer(rul1)
                                elif cha==uniquestring1[1]:
                                    code +=codereplacer(rul2)
                            print(code)
                            print(uniquestring1[0],rul1)
                            print(uniquestring1[1],rul2)
                            print(LastString)
                            if code == LastString:
                                axiom1=uniquestring1[0]
                                axiom2=uniquestring1[1]
                                externalrul1=rul1
                                externalrul2=rul2
                                print('rules are found')
                                print("First RULE:", uniquestring1[0], rul1)
                                print("Second RULE:", uniquestring1[1], rul2)
                                findsubgeneration(code, axiom1, rul1, axiom2, rul2)
                                return
                    rul1 = rul1[:o] + uniquestring1[i] + rul1[(o + 1):]
            rul1 += codereplacer(uniquestring1[i])
        rul2 = rul2[:z] + uniquestring1[m] + rul2[(z + 1):]
        rul1 =""
     rul2 += codereplacer(uniquestring1[m])
From what I understand from your comment, using itertools did solve your problems.

Here are a few suggestions anyway (that you may want to take into account before submitting a new question with the updated code):


instead of using global variables, you should add parameters to your functions.
you could take this chance to add a proper documentation about what your function is supposed to do and what the parameters are.
the indentations seem to be of various sizes. PEP8, the Style Guide for Python code recommands using 4 spaces. It is probably worth reading the whole document.