def test_NoCipher_WithSteg_WAV(self): for i in range(MAX_COVER_NOISE): # Encode jt65msgs = ["KB2BBC KA1AAB DD44", "KA1AAB KB2BBC DD44"] jt65data = jts.jt65encodemessages(jt65msgs, False) stegmsg = "BEACON FTW AND DEF CON 22" key = ''.join(random.choice(string.ascii_letters + string.digits) for n in xrange(random.randint(10, 30))) hidekey = jts.getnoisekey(key) cipherdata = jts.createciphermsgs( len(jt65data), stegmsg, "none", "", "", "", False) finalmsgs = jts.steginject(jt65data, i, cipherdata, hidekey, False) for index, value in enumerate(finalmsgs): tones = jt65sound.toneswithsync(value) jt65sound.outputwavfile( "test_output-00" + str(index) + ".wav", tones) # Decode result1 = jt65sound.inputwavfile("test_output-000.wav") result2 = jt65sound.inputwavfile("test_output-001.wav") symbols1, confidence1, wavmsg1, s2db, freq, a1, a2 = result1[0] symbols2, confidence2, wavmsg2, s2db, freq, a1, a2 = result2[0] os.remove("test_output-000.wav") os.remove("test_output-001.wav") finalresultmsgs = [symbols1, symbols2] stegdata = jts.retrievesteg(finalresultmsgs, hidekey, False) resultstegmsg = jts.deciphersteg(stegdata, "none", "", "", False) decodedjt65msgs = jts.decodemessages(finalresultmsgs, False) self.assertEqual(len(result1), 1) self.assertEqual(len(result2), 1) self.assertEqual(len(decodedjt65msgs), len(jt65msgs)) for i in range(len(jt65msgs)): self.assertEqual( jt65msgs[i].rstrip(), decodedjt65msgs[i].rstrip()) self.assertEqual(stegmsg.rstrip(), resultstegmsg.rstrip())
def test_AES_CFB_WAV(self): for i in range(MAX_COVER_NOISE): # Encode jt65msgs = [ "KB2BBC KA1AAB DD44", "KA1AAB KB2BBC DD44", "KB2BBC KA1AAB DD44", "KA1AAB KB2BBC DD44" ] jt65data = jts.jt65encodemessages(jt65msgs, False) stegmsg = "DEF CON 22" key = ''.join( random.choice(string.ascii_letters + string.digits) for n in xrange(random.randint(10, 30))) hidekey = jts.getnoisekey(key) cipherdata = jts.createciphermsgs( len(jt65data), stegmsg, "AES", "AES is totes secure, right? Yeah", "", "CFB", False) finalmsgs = jts.steginject(jt65data, i, cipherdata, hidekey, False) for index, value in enumerate(finalmsgs): tones = jt65sound.toneswithsync(value) jt65sound.outputwavfile("test_output-00" + str(index) + ".wav", tones) # Decode result1 = jt65sound.inputwavfile("test_output-000.wav") result2 = jt65sound.inputwavfile("test_output-001.wav") result3 = jt65sound.inputwavfile("test_output-002.wav") result4 = jt65sound.inputwavfile("test_output-003.wav") symbols1, confidence1, wavmsg1, s2db, freq, a1, a2 = result1[0] symbols2, confidence2, wavmsg2, s2db, freq, a1, a2 = result2[0] symbols3, confidence3, wavmsg3, s2db, freq, a1, a2 = result3[0] symbols4, confidence4, wavmsg4, s2db, freq, a1, a2 = result4[0] os.remove("test_output-000.wav") os.remove("test_output-001.wav") os.remove("test_output-002.wav") os.remove("test_output-003.wav") finalresultmsgs = [symbols1, symbols2, symbols3, symbols4] stegdata = jts.retrievesteg(finalresultmsgs, hidekey, False) resultstegmsg = jts.deciphersteg( stegdata, "AES", "AES is totes secure, right? Yeah", "CFB", False) decodedjt65msgs = jts.decodemessages(finalresultmsgs, False) self.assertEqual(len(result1), 1) self.assertEqual(len(result2), 1) self.assertEqual(len(result3), 1) self.assertEqual(len(result4), 1) self.assertEqual(len(decodedjt65msgs), len(jt65msgs)) for i in range(len(jt65msgs)): self.assertEqual(jt65msgs[i].rstrip(), decodedjt65msgs[i].rstrip()) self.assertEqual(stegmsg.rstrip(), resultstegmsg.rstrip())
def processinput(stdin, wavin, verbose): # Process input from stdin or wavs and return array of JT65 data JT65data = [] if stdin: stdinput = sys.stdin.readlines() n = 0 # Used to track which message you are on, if multiple messages were input at one time for index, value in enumerate(stdinput): if value.startswith("["): # Filter to only JT65 messages, allows usage with output from --encode --verbose if verbose: print "Raw Message " + str(n) + " : " + value numpymsg = np.fromstring( value.replace("[", "").replace("]", ""), dtype=int, sep=" " ) # Parses strings from the --stdout option JT65data.append(numpymsg) n = n + 1 elif verbose: print value # Shows any warnings, errors, or verbose output from stdin elif wavin: wavfiles = wavin.split(",") for index, value in enumerate(wavfiles): messages = jt65sound.inputwavfile(value, verbose) for currentmsg in messages: symbols, confidence, msg, s2db, freq, a1, a2 = currentmsg numpymsg = np.array(symbols) JT65data.append(numpymsg) return JT65data
def test_NoCipher_NoSteg_WAV(self): # Encode jt65msgs = ["KB2BBC KA1AAB DD44", "KA1AAB KB2BBC DD44"] jt65data = jts.jt65encodemessages(jt65msgs, False) for index, value in enumerate(jt65data): tones = jt65sound.toneswithsync(value) jt65sound.outputwavfile("test_output-00" + str(index) + ".wav", tones) # Decode result1 = jt65sound.inputwavfile("test_output-000.wav") result2 = jt65sound.inputwavfile("test_output-001.wav") symbols1, confidence1, wavmsg1, s2db, freq, a1, a2 = result1[0] symbols2, confidence2, wavmsg2, s2db, freq, a1, a2 = result2[0] os.remove("test_output-000.wav") os.remove("test_output-001.wav") resultjt65data = [symbols1, symbols2] decodedjt65msgs = jts.decodemessages(resultjt65data, False) self.assertEqual(len(result1), 1) self.assertEqual(len(result2), 1) self.assertEqual(len(decodedjt65msgs), len(jt65msgs)) for i in range(len(jt65msgs)): self.assertEqual(jt65msgs[i].rstrip(), decodedjt65msgs[i].rstrip())
def test_NoCipher_NoSteg_WAV(self): # Encode jt65msgs = ["KB2BBC KA1AAB DD44", "KA1AAB KB2BBC DD44"] jt65data = jts.jt65encodemessages(jt65msgs, False) for index, value in enumerate(jt65data): tones = jt65sound.toneswithsync(value) jt65sound.outputwavfile( "test_output-00" + str(index) + ".wav", tones) # Decode result1 = jt65sound.inputwavfile("test_output-000.wav") result2 = jt65sound.inputwavfile("test_output-001.wav") symbols1, confidence1, wavmsg1, s2db, freq, a1, a2 = result1[0] symbols2, confidence2, wavmsg2, s2db, freq, a1, a2 = result2[0] os.remove("test_output-000.wav") os.remove("test_output-001.wav") resultjt65data = [symbols1, symbols2] decodedjt65msgs = jts.decodemessages(resultjt65data, False) self.assertEqual(len(result1), 1) self.assertEqual(len(result2), 1) self.assertEqual(len(decodedjt65msgs), len(jt65msgs)) for i in range(len(jt65msgs)): self.assertEqual(jt65msgs[i].rstrip(), decodedjt65msgs[i].rstrip())
def performwavdecode(filename, stegcollection): # Decode a single wav file containssteg = False messages = jt65sound.inputwavfile(filename, verbose=args.verbose) for currentmsg in messages: symbols, confidence, msg, s2db, freq, a1, a2 = currentmsg numpymsg = np.array(symbols) jt65data = [] jt65data.append(numpymsg) jt65datacopy = copy.deepcopy( jt65data ) # Necessary on some version of Python due to 'unprepmsg' not preserving list # Retrieve JT65 valid messages jt65msgs = jts.decodemessages(jt65data, args.verbose) if STEG_ENABLED: containssteg = jts.validatesteg(jt65msgs[0], symbols, hidekey, STEG_DETECTION_ERROR_THRESHOLD, args.verbose) if containssteg: # Retrieve steg message stegdata = jts.retrievesteg( jt65datacopy, hidekey, args.verbose, True) # Unprep the steg to get actual bytes stegcollection.append(stegdata[0]) # Determine if we have a steg result containsstegresult, stegstatus, resetcollection, stegmsg = getstegresult( stegcollection, args.cipher, args.key, args.aesmode, args.verbose) if resetcollection: stegcollection[:] = [ ] # Reset the steg collection for the next incoming message # Print result for index, value in enumerate(jt65msgs): print "\nDecoded JT65 message " + str( index ) + " : " + colorama.Fore.BLUE + value + colorama.Fore.RESET if containssteg and containsstegresult: print "\nHidden message : " + colorama.Fore.RED + stegmsg + colorama.Fore.RESET elif containssteg: print "\n" + colorama.Fore.RED + "Steg detected! " + colorama.Fore.YELLOW + stegstatus + colorama.Fore.RESET
def performwavdecode(filename, stegcollection): # Decode a single wav file containssteg = False messages = jt65sound.inputwavfile(filename, verbose=args.verbose) for currentmsg in messages: symbols, confidence, msg, s2db, freq, a1, a2 = currentmsg numpymsg = np.array(symbols) jt65data = [] jt65data.append(numpymsg) jt65datacopy = copy.deepcopy( jt65data ) # Necessary on some version of Python due to 'unprepmsg' not preserving list # Retrieve JT65 valid messages jt65msgs = jts.decodemessages(jt65data, args.verbose) if STEG_ENABLED: containssteg = jts.validatesteg(jt65msgs[0], symbols, hidekey, STEG_DETECTION_ERROR_THRESHOLD, args.verbose) if containssteg: # Retrieve steg message stegdata = jts.retrievesteg( jt65datacopy, hidekey, args.verbose, True ) # Unprep the steg to get actual bytes stegcollection.append(stegdata[0]) # Determine if we have a steg result containsstegresult, stegstatus, resetcollection, stegmsg = getstegresult( stegcollection, args.cipher, args.key, args.aesmode, args.verbose ) if resetcollection: stegcollection[:] = [] # Reset the steg collection for the next incoming message # Print result for index, value in enumerate(jt65msgs): print "\nDecoded JT65 message " + str(index) + " : " + colorama.Fore.BLUE + value + colorama.Fore.RESET if containssteg and containsstegresult: print "\nHidden message : " + colorama.Fore.RED + stegmsg + colorama.Fore.RESET elif containssteg: print "\n" + colorama.Fore.RED + "Steg detected! " + colorama.Fore.YELLOW + stegstatus + colorama.Fore.RESET
def processinput(stdin, wavin, verbose): # Process input from stdin or wavs and return array of JT65 data JT65data = [] if stdin: stdinput = sys.stdin.readlines() n = 0 # Used to track which message you are on, if multiple messages were input at one time for index, value in enumerate(stdinput): if value.startswith( "[" ): # Filter to only JT65 messages, allows usage with output from --encode --verbose if verbose: print "Raw Message " + str(n) + " : " + value numpymsg = np.fromstring( value.replace('[', '').replace(']', ''), dtype=int, sep=' ') # Parses strings from the --stdout option JT65data.append(numpymsg) n = n + 1 elif verbose: print value # Shows any warnings, errors, or verbose output from stdin elif wavin: wavfiles = wavin.split(",") for index, value in enumerate(wavfiles): messages = jt65sound.inputwavfile(value, verbose) for currentmsg in messages: symbols, confidence, msg, s2db, freq, a1, a2 = currentmsg numpymsg = np.array(symbols) JT65data.append(numpymsg) return JT65data