Blogger PostOrkutBookmark/FavoritesEmailFacebookTwitterShare

Encontrei um código muito interessante no site: http://www.evanfosmark.com/2008/06/xor-encryption-with-python/

É um código simples e recursivo, que busca todas as possibilidades de letras maiucuslas e minusculas a partir de uma string.

def recurse (pref,suff):
    # If no characters left, just print prefix.

    if suff == "":
            print pref
            return

    # Otherwise add lowercase of first suffix letter to prefix
    # and recur with that and the remainder of the suffix.
    # Then do the same for uppercase.
    # We also detect if the upper and lower are the same
    # and only recurse once.

    if suff[0:1].lower() == suff[0:1].upper():
        recurse (pref + suff[0:1], suff[1:])
    else:
        recurse (pref + suff[0:1].lower(), suff[1:])
        recurse (pref + suff[0:1].upper(), suff[1:])

# Test the function with "Ben!!!".

recurse ("","abc!")

Entrada:
abc!

Saida:
abc!
abC!
aBc!
aBC!
Abc!
AbC!
ABc!
ABC!