I wanted to know if the algorithm that i wrotte just below in python is correct.
My goal is to find an algorithm that print/find all the possible combinaison of words that can be done using the character from character '!' (decimal value = 33) to character '~' (decimal value = 126) in the asccii table:
Here the code using recursion in python:
byteWord = bytearray(b'\x20') # Hex = '\x21' & Dec = '33' & Char = '!'
cntVerif = 0
def comb_fct(bytes_arr, cnt: int):
global cntVerif
if len(bytes_arr) > 3:
print(f'{cntVerif+1}:TEST END')
sys.exit()
if bytes_arr[cnt] == 126:
if cnt == len(bytes_arr) or len(bytes_arr) == 1:
bytes_arr.insert(0, 32)
bytes_arr[cnt] = 32
cnt += 1
cntVerif += 1
print(f'{cntVerif}:if bytes_arr[cnt] == 126: \n\tbytes_arr = {bytes_arr}')
comb_fct(bytes_arr, cnt)
if cnt == -1 or cnt == len(bytes_arr)-1:
bytes_arr[cnt] = bytes_arr[cnt] + 1
cntVerif += 1
print(f'{cntVerif}:if cnt==-1: \n\tbytes_arr = {bytes_arr}')
comb_fct(bytes_arr, cnt=-1) # index = -1 means last index
bytes_arr[cnt] = bytes_arr[cnt] + 1
cntVerif += 1
print(f'{cntVerif}:None if: \n\tbytes_arr={bytes_arr}')
comb_fct(bytes_arr, cnt+1)
comb_fct(byteWord, -1)
Pseudo-code:
byteWord = bytearray(b'\x20') # create a byte with value 20 in hex basis
cntVerif = 0
def comb_fct(bytes_arr, cnt: int):
if length(bytes_arr) > 3:
print(f'{cntVerif+1}:TEST END')
stop
if bytes_arr[cnt] == 126:
if cnt == length(bytes_arr) or length(bytes_arr) == 1:
bytes_arr.insert(index=0, value=32) # Insert at the top of the byte array an other byte at index 0 (the begining) with value 32
bytes_arr[cnt] = 32
cnt += 1
cntVerif += 1
print(f'{cntVerif}:if bytes_arr[cnt] == 126: \n\tbytes_arr = {bytes_arr}')
comb_fct(bytes_arr, cnt)
if cnt == -1 or cnt == len(bytes_arr)-1:
bytes_arr[cnt] = bytes_arr[cnt] + 1
cntVerif += 1
print(f'{cntVerif}:if cnt==-1: \n\tbytes_arr = {bytes_arr}')
comb_fct(bytes_arr, cnt=-1) # index = -1 means last index
bytes_arr[cnt] = bytes_arr[cnt] + 1
cntVerif += 1
print(f'{cntVerif}:None if: \n\tbytes_arr={bytes_arr}')
brute_force_fct(bytes_arr, cnt+1)
comb_fct(byteWord, -1)
Thank your for your help because python allow just a limited number of recursion (996 on my computer) so for exemple i can't verify if my algorithm give all the word of length 3 that can be realised with the range of character describe upper.
And more generally i would like to know if my algorithm is correct genrally (the logic).
Of course if anyone has a better idea to writte this algorithm (a faster algorithm for exemple). I will be happy to read it.