def decrypter_function(args): # Get the ciphertext from CLI or file if args.ciphertext is not None: cipher_txt = args.ciphertext else: # It's a file cipher_txt = args.filename.read() # If specific decoder set (else use all decoders) if args.decoder is not None: logging.info('Use specific decoder: ' + args.specific) decoder = DECODERS_MAP[args.specific] results = decoder(cipher_txt) if results == []: return 'No result found' result = '' for i, plaintext in enumerate(results): result += '[' + str(i + 1) + '] Result: ' + plaintext + '\n\n' return result # If specific evaluator set (else use all evaluators) functions_string = ['F', 'F', 'F'] flag_format = '' if args.checkLetter or args.checkWord or args.checkFlag: if args.checkLetter: functions_string[0] = 'T' logging.info('Add specific evaluator: letter analysis') if args.checkWord: functions_string[1] = 'T' logging.info('Add specific evaluator: word analysis') if args.checkFlag: functions_string[2] = 'T' logging.info('Add specific evaluator: flag search') flag_format = args.checkFlag functions_string = ''.join(functions_string) else: logging.info('Use all evaluators') functions_string = 'TTT' # Try all decoders plaintexts = [] logging.info('Decode ciphertext by Caesar decoder') plaintexts += CaesarDecoder.safe_decode(cipher_txt) logging.info('Decode ciphertext by ASCII decoder') plaintexts += ASCIIDecoder.safe_decode(cipher_txt) logging.info('Decode ciphertext by Base64 decoder') plaintexts += Base64Decoder.safe_decode(cipher_txt) logging.info('Decode ciphertext by Reverse decoder') plaintexts += ReverseDecoder.safe_decode(cipher_txt) logging.info('Decode ciphertext by hash decoder') plaintexts += HashDecoder.safe_decode(cipher_txt) # Create result string result = '' evaluatedPlaintexts = evaluate(plaintexts, functions_string, flag_format)[0:args.number] for i, plaintext in enumerate(evaluatedPlaintexts): result += '[' + str(i + 1) + '] Result: ' + plaintext[0] + '\n\n' return result
def test_validate_false_not_printable_value(): assert (ASCIIDecoder.validate('1 104 105 115 32 105 115 32 97 32 84 101 115 116 33') == False)
def test_validate_true(): assert (ASCIIDecoder.validate('84 104 105 115 32 105 115 32 97 32 84 101 115 116 33') == True)
def test_safe_decode_not_numbers(): assert (ASCIIDecoder.safe_decode('1 2sad 1!5 115 32 1$5 115 32 97 32 84 101 115 116 33') == [])
def test_safe_decode_not_printable_ascii(): assert (ASCIIDecoder.safe_decode('1 104 105 115 32 105 115 32 97 32 84 101 115 116 33') == [])
def test_safe_decode_true(): assert (ASCIIDecoder.safe_decode('84 104 105 115 32 105 115 32 97 32 84 101 115 116 33') == ['This is a Test!'])
def test_validate_false(): assert (ASCIIDecoder.validate('84d104s300 115 32 105 115 32 97 32 84 101 115 116 33') == False)