-1

I want to create a bruteforcing method using the alphabet.

For example :

x = input("What is your password ?")
length = len(x)

Then the program will check every single combination alphabettically like:

aa,ab,ac,ad and so on.

I have tried one method like:

for c in printable:
    r = c
    status = r
    for c in printable:
        r = (f"{status}{c}")

And this method breaks in the 3rd loop.

Is there a way I can do this?

3 Answers3

1

you can use itertools module of python.

import itertools
import string

length = N

for combinaison in itertools.product(string.ascii_lowercase, repeat=length):
    print(''.join(combinaison ))
Kaz
  • 1,047
  • 8
  • 18
1

something like this maybe (suppose length of the password is not known):

from itertools import permutations

password = input()

for i in range(1, len(password) + 1):
    for p in permutations(password, i):
        print(p)

for input like 'abc' the output will be:

('a',)
('b',)
('c',)
('a', 'b')
('a', 'c')
('b', 'a')
('b', 'c')
('c', 'a')
('c', 'b')
('a', 'b', 'c')
('a', 'c', 'b')
('b', 'a', 'c')
('b', 'c', 'a')
('c', 'a', 'b')
('c', 'b', 'a')
tetris555
  • 335
  • 1
  • 2
  • 8
0

If you want to do it yourself - here's the way.

If you have an alphabet, e.g. ['a', 'b', 'c', 'd', 'e'], which has N distinct characters, you can try to interpret numbers with base N. For example for alphabet of size 5, can interpret 112 as 422 (4*5^2 + 2*5^1 + 2*5^0). Then using this 422 representation, you index the alphabet 4 is letter 'e', 2 is letter 'c'. Thus you interpret decimalnumber 112 as password 'ecc'. Finally to burteforce you try every decimal number from 1 to something big, and iterpret each as I described.

alphabet = ['a', 'b', 'c', 'd', 'e']
max_length = 5
max_bruteforce = len(alphabet)**max_length

for attempt in range(max_bruteforce):
    password = ''
    while attempt > 0:
        letter_i = int(attempt % len(alphabet))
        letter = alphabet[letter_i]
        password = letter + password
        attempt = attempt // len(alphabet)
    print(password)
Alexey S. Larionov
  • 6,555
  • 1
  • 18
  • 37