コード例 #1
0
 def test_Decode(self):
     msg1 = np.array([34, 20, 5, 42, 26, 9, 3, 5, 60, 6, 24, 22])
     msg2 = np.array([34, 16, 49, 31, 2, 9, 16, 22, 41, 38, 24, 22])
     expectedresult1 = "KB2BBC KA1AAB DD44"
     expectedresult2 = "KA1AAB KB2BBC DD44"
     result1 = jt.decode(msg1).rstrip()
     result2 = jt.decode(msg2).rstrip()
     self.assertEqual(len(result1), len(expectedresult1))
     self.assertEqual(len(result2), len(expectedresult2))
     self.assertEqual(result1, expectedresult1)
     self.assertEqual(result2, expectedresult2)
コード例 #2
0
def decodemessages(jt65data, verbose=False):
# Decode valid JT65 messages from array of JT65 data
    jt65msgs = []

    for index, value in enumerate(jt65data):
        jt65msg = jt.decode(jt.unprepmsg(value))
        if verbose:
            print "JT65 Message " + str(index) + " : " + jt65msg
        jt65msgs.append(jt65msg)

    return jt65msgs
コード例 #3
0
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