def test_UnPrepSteg(self): msg1 = np.array( [47, 44, 14, 33, 4, 58, 19, 6, 16, 52, 50, 11, 6, 13, 41, 26, 39, 15, 39, 11]) msg2 = np.array( [22, 29, 9, 53, 17, 23, 57, 14, 20, 36, 39, 11, 59, 23, 28, 16, 53, 8, 57, 0]) expectedresult1 = np.array( [16, 52, 50, 11, 6, 13, 41, 26, 39, 15, 39, 11]) expectedresult2 = np.array( [20, 36, 39, 11, 59, 23, 28, 16, 53, 8, 57, 0]) result1 = jt.unprepsteg(msg1) result2 = jt.unprepsteg(msg2) self.assertEqual(len(result1), len(expectedresult1)) self.assertEqual(len(result2), len(expectedresult2)) self.assertEqual(result1.tolist(), expectedresult1.tolist()) self.assertEqual(result2.tolist(), expectedresult2.tolist())
def retrievesteg(jt65data, hidekey, verbose=False, unprep=False): # Retrieve steganography data from array of JT65 data stegdata = [] for index, value in enumerate(jt65data): data = jtunsteg(value, hidekey) if verbose: print "Steg Bytes in Message " + str(index) + " : " + str(data) if unprep: data = jt.unprepsteg(data) stegdata.append(data) return stegdata
def deciphersteg(stegdata, cipher, key, aesmode, verbose=False, unprep=True): # Decipher hidden message from array of data hidden in JT65 errors stegedmsg = "" stegedmsgba = np.array(range(0), dtype=np.int32) statusar = [] for index, value in enumerate(stegdata): if unprep: value = jt.unprepsteg(value) # Decode real data from FEC if cipher == "none": recoveredtext = jt.decode(value)[0:13] if verbose: print "Steg Text in Message " + str(index) + " : " + recoveredtext stegedmsg += recoveredtext elif cipher == "XOR" or cipher == "OTP": thesebytes = jt65tobytes(value) thisstatus = thesebytes[0:1] if thisstatus & 0x40 == 0x40: # This is the last packet, signals how many bytes to read bytestoread = thisstatus & 0x3F thisunstegbytes = thesebytes[1:bytestoread + 1] else: thisunstegbytes = thesebytes[1:] if verbose: print "Steg Data in Message " + str(index) + " : " + str(thisunstegbytes) stegedmsgba = np.append(stegedmsgba, thisunstegbytes) else: thesebytes = jt65tobytes(value) thisunstegbytes = thesebytes[1:10] if verbose: print "Steg Data in Message " + str(index) + " : " + str(thisunstegbytes) stegedmsgba = np.append(stegedmsgba, thisunstegbytes) if cipher == "XOR": if verbose: print"Cipher Data : " + str(stegedmsgba) finalcipherdata = ( ''.join('{0:02x}'.format(int(e)).decode("hex") for e in stegedmsgba)) if verbose: print"Cipher Data Hex : " + finalcipherdata cryptobj = XOR.new(key) stegedmsg = cryptobj.decrypt(finalcipherdata) if cipher == "ARC4": if verbose: print"Cipher Data : " + str(stegedmsgba) finalcipherdata = ( ''.join('{0:02x}'.format(int(e)).decode("hex") for e in stegedmsgba)) if verbose: print"Cipher Data Hex : " + finalcipherdata tempkey = SHA.new(key).digest() cryptobj = ARC4.new(tempkey) stegedmsg = cryptobj.decrypt(finalcipherdata) if cipher == "AES": if verbose: print"Cipher Data : " + str(stegedmsgba) finalcipherdata = ( ''.join('{0:02x}'.format(int(e)).decode("hex") for e in stegedmsgba)) if verbose: print"Cipher Data Hex : " + finalcipherdata if aesmode == "ECB": cryptobj = AES.new(key, AES.MODE_ECB) elif aesmode == "CBC": cryptobj = AES.new(key, AES.MODE_CBC, finalcipherdata[0:16]) finalcipherdata = finalcipherdata[16:] elif aesmode == "CFB": cryptobj = AES.new(key, AES.MODE_CFB, finalcipherdata[0:16]) finalcipherdata = finalcipherdata[16:] stegedmsg = cryptobj.decrypt(finalcipherdata) if cipher == "GPG": if verbose: print"Cipher Data : " + str(stegedmsgba) finalcipherdata = ( ''.join('{0:02x}'.format(int(e)).decode("hex") for e in stegedmsgba)) if verbose: print"Cipher Data Hex : " + finalcipherdata gpg = GPG() stegedmsg = gpg.decrypt(finalcipherdata) stegedmsg = str(stegedmsg) if cipher == "OTP": finalcipherdata = (''.join(chr(e) for e in stegedmsgba)) if verbose: print"Cipher Data : " + str(finalcipherdata) stegedmsg = otp_decode(str(finalcipherdata), key) return stegedmsg