def generate_standard_token(cls, starting_code, key, value, count, mode=OPAYGOShared.TOKEN_TYPE_SET_TIME, restricted_digit_set=False): # We get the first 3 digits with encoded value starting_code_base = OPAYGOShared.get_token_base(starting_code) token_base = cls._encode_base(starting_code_base, value) current_token = OPAYGOShared.put_base_in_token(starting_code, token_base) current_count_odd = count % 2 if mode == OPAYGOShared.TOKEN_TYPE_SET_TIME: if current_count_odd: # Odd numbers are for Set Time new_count = count + 2 else: new_count = count + 1 else: if current_count_odd: # Even numbers are for Add Time new_count = count + 1 else: new_count = count + 2 for xn in range(0, new_count): current_token = OPAYGOShared.generate_next_token( current_token, key) final_token = OPAYGOShared.put_base_in_token(current_token, token_base) if restricted_digit_set: final_token = OPAYGOShared.convert_to_4_digit_token(final_token) return new_count, final_token
def get_activation_value_count_and_type_from_token( cls, token, starting_code, key, last_count, restricted_digit_set=False, used_counts=None): if restricted_digit_set: token = OPAYGOShared.convert_from_4_digit_token(token) valid_older_token = False token_base = OPAYGOShared.get_token_base( token) # We get the base of the token current_code = OPAYGOShared.put_base_in_token( starting_code, token_base) # We put it into the starting code starting_code_base = OPAYGOShared.get_token_base( starting_code) # We get the base of the starting code value = cls._decode_base( starting_code_base, token_base) # If there is a match we get the value from the token # We try all combination up until last_count + TOKEN_JUMP, or to the larger jump if syncing counter # We could start directly the loop at the last count if we kept the token value for the last count if value == OPAYGOShared.COUNTER_SYNC_VALUE: max_count_try = last_count + cls.MAX_TOKEN_JUMP_COUNTER_SYNC + 1 else: max_count_try = last_count + cls.MAX_TOKEN_JUMP + 1 for count in range(0, max_count_try): masked_token = OPAYGOShared.put_base_in_token( current_code, token_base) if count % 2: type = OPAYGOShared.TOKEN_TYPE_SET_TIME else: type = OPAYGOShared.TOKEN_TYPE_ADD_TIME if masked_token == token: if cls._count_is_valid(count, last_count, value, type, used_counts): return value, count, type else: valid_older_token = True current_code = OPAYGOShared.generate_next_token( current_code, key) # If not we go to the next token if valid_older_token: return -2, None, None return None, None, None
from encode_token import OPAYGOEncoder from shared import OPAYGOShared import codecs # We know the starting code, and we know 3 tokens with count and value known_value = 7 code_count_1 = int('016609796') code_count_2 = int('395084796') code_count_3 = int('566856796') starting_code = 123456789 if __name__ == '__main__': print('Trying to bruteforce the starting code...') token_base = OPAYGOShared.get_token_base(code_count_1) - known_value for i in range(2**64): if i % 10000 == 0: print(str(round((i / (2**64)) * 100, 10)) + '%') device_key = i.to_bytes(16, 'big') #print(device_key) activation_code = OPAYGOEncoder.generate_standard_token( starting_code=starting_code, key=device_key, value=known_value, count=1 + 1) if activation_code == code_count_1:
from shared import OPAYGOShared import codecs # We know the key, and we know 3 tokens with count and value known_value = 7 code_count_1 = int('016609796') code_count_2 = int('395084796') code_count_3 = int('682637796') device_key_hex = 'a29ab82edc5fbbc41ec9530f6dac86b1' device_key = codecs.decode(device_key_hex, 'hex') if __name__ == '__main__': print('Trying to bruteforce the starting code...') token_base = OPAYGOShared.get_token_base(code_count_1) - known_value for i in range(999999): if i % 10000 == 0: print(str(int((i/999999)*100))+'%') starting_code = OPAYGOShared.put_base_in_token(i*1000, token_base) count, activation_code = OPAYGOEncoder.generate_standard_token( starting_code=starting_code, key=device_key, value=known_value, count=1, mode=OPAYGOShared.TOKEN_TYPE_ADD_TIME )