I’m coding in python and I have a script that generates all combinations of an 85 character string. There is a custom mapping that maps the characters in the strings to a number so I can choose which strings come first or last. I set v to the lowest character in my mapping and I want to then add 10 vs to a chosen string that will be generated in the future so that it will come first. Only one string will have the vs added so that it’s the only string that comes first.
My code is:
import itertools
import string
hex_characters = '0123456789abcdef' # Exclude 'abcdef' since 'ABCDEF' is in 'string.hexdigits'
repeat = 85
product_generator = itertools.product(hex_characters, repeat=repeat)
def custom_mapping(hex_string):
# Define the custom mapping here
char_to_number = {
'0': 16,
'1': 1,
'2': 2,
'3': 3,
'4': 4,
'5': 5,
'6': 6,
'7': 0,
'8': 8,
'9': 9,
'a': 10,
'b': 11,
'c': 12,
'd': 13,
'e': 14,
'f': 15,
'v': -1
}
# Sort characters according to the custom mapping
sorted_chars = sorted(hex_string, key=lambda char: char_to_number[char])
return ''.join(sorted_chars)
def onlyFunction2(combinations, exclude_char=''):
return (comb for comb in combinations if exclude_char not in comb)
filtered_combinations = onlyFunction2(product_generator, exclude_char='7')
for combination in filtered_combinations:
hex_string = ''.join(combination)
mapped_string = custom_mapping(hex_string)
print(mapped_string)
As you can see, in onlyFunction2, there is a part where I can exclude a specific characgter and it can skip over that character. While excluding a character I want to also add 10 vs to a chosen substring that will be 40 characters long. I am going to edit my code myself so that only one substring for each iteration will be valid. If you guys can help me add 10 vs to a chosen substring, since my mapping sets v to -1 that substring will come first, and there will only be one of that string with the substring in it (when I edit my code again).