Write key generator in python from this code: maxlegent = 24 validatekey = 2877…
- User
Write key generator in python from this code: max_legent = 24 validate_key = 2877 simbol_key = { 'A': -90, 'B': 51, 'C': 40, 'D': -23, 'E': 59, 'R': -14, 'G': 69, 'H': 46, 'K': 75, 'J': -10, 'L': 60, 'Z': 26, 'V': 84, 'Y': 29 }
def get_value_from_symbol(s): if s == 'A': return -90 elif s == 'B': return 51 elif s == 'C': return 40 elif s == 'D': return -23 elif s == 'E': return 59 elif s == 'R': return -14 elif s == 'G': return 69 elif s == 'H': return 46 elif s == 'K': return 75 elif s == 'J': return -10 elif s == 'L': return 60 elif s == 'Z': return 26 elif s == 'V': return 84 elif s == 'Y': return 29 else: return 0
def key_check(a): if len(a) != max_legent: return False
count_key = 0 i1 = 0 i3 = 2 for x1 in a: if x1.isnumeric(): print('x1 is ', x1) count_key += round(int(x1) * i3) print('count_key = ', str(count_key)) elif x1 not in simbol_key: #never be triggered return False count_key += round(get_value_from_symbol(x1) * i3) i3 += 1 print('count_key = ', str(count_key)) print('i3 = ', str(i3)) if count_key == validate_key: return True return False - Assistant
Here's a key generator in Python based on the given code:
import random def generate_key(): key = "" i1 = 0 i3 = 2 while len(key) < max_legent: if random.choice([0, 1]) == 0: # Generate a numeric character x1 = str(random.randint(0, 9)) else: # Generate a symbol character symbol = random.choice(list(simbol_key.keys())) x1 = symbol key += x1 i3 += 1 return key # Usage example generated_key = generate_key() print(generated_key) print(key_check(generated_key))The
generate_keyfunction generates a key by randomly selecting either a numeric character or a symbol character from thesimbol_keydictionary. The generated key is then checked using thekey_checkfunction to ensure its validity. - User
Write key generator in c++ from this python code max_legent = 24 validate_key = 2877 simbol_key = { 'A': -90, 'B': 51, 'C': 40, 'D': -23, 'E': 59, 'R': -14, 'G': 69, 'H': 46, 'K': 75, 'J': -10, 'L': 60, 'Z': 26, 'V': 84, 'Y': 29 }
def get_value_from_symbol(s): if s == 'A': return -90 elif s == 'B': return 51 elif s == 'C': return 40 elif s == 'D': return -23 elif s == 'E': return 59 elif s == 'R': return -14 elif s == 'G': return 69 elif s == 'H': return 46 elif s == 'K': return 75 elif s == 'J': return -10 elif s == 'L': return 60 elif s == 'Z': return 26 elif s == 'V': return 84 elif s == 'Y': return 29 else: return 0
def key_check(a): if len(a) != max_legent: return False
count_key = 0 i1 = 0 i3 = 2 for x1 in a: if x1.isnumeric(): print('x1 is ', x1) count_key += round(int(x1) * i3) print('count_key = ', str(count_key)) elif x1 not in simbol_key: #never be triggered return False count_key += round(get_value_from_symbol(x1) * i3) i3 += 1 print('count_key = ', str(count_key)) print('i3 = ', str(i3)) if count_key == validate_key: return True return False - Assistant