CwhatC CwhatC - 2 months ago 3x
Python Question

Python generating a range of numbers that have no same digits & unique

i am trying to figure out how to generate a list of numbers that are not only unique but also have no similar digits
The purpose is to crack sample hashes using crypt, what i know is the passwords are unique, no repeating digits and up to 6 digits


[1,2,3,4,5,6,7,8,9...120, 123,124,125,126,127... 123456,123457...]

so 122 or 123451 or 12345673 because there will be repeating numbers

my code

#!/usr/bin/env python

from os import getuid
from crypt import crypt
import time

# all initialisation here
password = range(1000000)
# all initialisation ends here

def VerifyHash(shadowHashes, salt, user):
# crypt("Message", "Salt")
for i in password:
if (shadowHashes == crypt(str(i),salt)):
print "Password of %s is " % user + str(i)

def main():
with open('shadow.txt') as p:
for line in p:
shadowList = line
shadowHashes = shadowList.split(':')[1]
user = shadowList.split(':')[0]
salt = shadowHashes[:12]
print "Program completed time: " + time.strftime('%x %X')

print "Program started time: " + time.strftime('%x %X')

for now i am using range(1000000) and it works but is inefficient because the numbers i'm comparing to are unique with no repeating digits so i want to make my python program more efficient

Please point me in the right direction


You could check if the length of the number when represented as a string is the same when the digits in the number are placed in a set:

def unique_count():
    for i in range(1000000):
        if len(str(i)) == len(set(str(i))):
            yield i

The set eliminates duplicate digits, so numbers that do not have duplicated digits will pass the condition.