def extract_PIN(encrypted_PIN): """Extracts the original PIN string from an encrypted PIN.""" # Return an integer. # Brute force all the options atm = ATM() for pin in xrange(1000, 10000): msg = atm.encrypt_PIN(pin) if msg == encrypted_PIN: return pin
def extract_PIN(encrypted_PIN): """Extracts the original PIN string from an encrypted PIN.""" # Return an integer. original_PIN = None possible_PIN_codes = create_all_possible_PIN() atm = ATM() for p in possible_PIN_codes: int_PIN = convert_digits_array_to_int(p) current_encrypted_PIN = atm.encrypt_PIN(int_PIN) if current_encrypted_PIN == encrypted_PIN: original_PIN = int_PIN break return original_PIN
def check_q2c(module_path): try: module = import_module(module_path) signature = module.forge_signature() except Exception as e: error('Exception forging a signature with {}', module_path) traceback.print_exc() return False if not isinstance(signature, ServerResponse): error('Signature should be a ServerResponse but is a {}', type(signature)) return False try: if not ATM().verify_server_approval(signature): error('Verification does not pass with signature from {}', module_path) except Exception as e: error('Exception while running the verification on response from {}', module_path) traceback.print_exc() return False return True
def extract_PIN(encrypted_PIN): atm = ATM() all_pin_combinations = itertools.product([i for i in range(10)], repeat=4) for i in range(10**4): temp_combination_arr = all_pin_combinations.next() temp_combination_str = "".join(str(digit) for digit in temp_combination_arr) temp_combination_int = int(temp_combination_str) if atm.rsa_pin.encrypt(temp_combination_int,None)[0] == encrypted_PIN: return int(temp_combination_int)
def extract_PIN(encrypted_PIN): """Extracts the original PIN string from an encrypted PIN.""" # Return an integer. #raise NotImplementedError() atm_try = ATM() for i in range(0, 11000): pin = getattr(atm_try, 'encrypt_PIN') if pin(i) == encrypted_PIN: return i return -1
def extract_credit_card(encrypted_credit_card): """Extracts a credit card number string from its ciphertext.""" # Return an integer. #raise NotImplementedError() atm_try = ATM() credit_num = getattr(atm_try, 'encrypt_credit_card') pin = int(round(encrypted_credit_card**(1.0 / 3))) pinT = pin**3 encr_credit_num = credit_num(pin) if (pinT == encrypted_credit_card ) and encr_credit_num == encrypted_credit_card: real_creadit_card = pin return real_creadit_card
def extract_credit_card(encrypted_credit_card): """Extracts a credit card number string from its ciphertext.""" # Return an integer. # This solution is correct only for small e import math atm = ATM() card_key = atm.rsa_card n = card_key.n e = card_key.e return int( math.ceil((10**(math.log(encrypted_credit_card, 10) / e))) ) # This is never an int, so need to take or floor or ceiling value. ceiling was decided
def check_q2b(module_path): return check_extraction(module_path, 'extract_credit_card', 'credit card', 123456789, ATM().encrypt_credit_card, (int, long))
def check_q2a(module_path): return check_extraction(module_path, 'extract_PIN', 'PIN', 1234, ATM().encrypt_PIN, (int, long))
def forge_signature(): atm_try = ATM() number = getattr(atm_try, 'encrypt_number') approval = atm_try.CODE_APPROVAL rsa_card = atm_try.rsa_card return ServerResponse(approval, number(rsa_card, approval))
def extract_PIN(encrypted_PIN): item = ATM() for i in range(10000): if (item.encrypt_PIN(i) == encrypted_PIN): return i