def GA_encoding(coverSamples, secretMessage, key, frameRate, fileType):
    # Deepcopy for calculating the SNR
    originalCoverSamples = deepcopy(coverSamples[0])

    for i in range(0, len(coverSamples[0])):
        coverSamples[0][i] = "{0:016b}".format(coverSamples[0][i])

    secretMessage = "".join(map(str, secretMessage))

    # Provide first audio channel samples and message samples to encode
    stegoSamples, samplesUsed, bitsInserted, capacityWarning = GA.insertMessage(
        coverSamples[0], key, "".join(map(str, secretMessage)), fileType)

    # Convert the binary audio samples to decimal samples
    for i in range(0, len(stegoSamples)):
        stegoSamples[i] = int(stegoSamples[i], 2)

    # Get the characteristics of the stego file
    infoMessage = "Embedded " + str(bitsInserted) + " bits into " + str(
        samplesUsed) + " samples."
    infoMessage += "\nSNR of " + str(
        round(
            RT.getSNR(originalCoverSamples[0:samplesUsed],
                      stegoSamples[0:samplesUsed]), 2))
    infoMessage += ".\nCapacity of " + str(
        RT.getCapacity(secretMessage, samplesUsed, frameRate)) + " kbps."

    return stegoSamples
Beispiel #2
0
def testGA(song, key):
    cover = wave.open(song, mode='rb')
    coverSamples = fp.extractWaveSamples(cover)

    message = "G" * int(16777200 / 8)
    secretMessage = fp.messageToBinary(message)
    originalCoverSamples = deepcopy(coverSamples[0])
    keyString = key
    binaryKey = fp.messageToBinary(keyString)
    binaryKey = binaryKey * int(
        (len(secretMessage) + float(len(secretMessage)) / len(binaryKey)))

    for i in range(0, len(coverSamples[0])):
        coverSamples[0][i] = "{0:016b}".format(coverSamples[0][i])

    secretMessage = "".join(map(str, secretMessage))
    stegoSamples, samplesUsed, bitsInserted, capacityWarning = GA.insertMessage(
        coverSamples[0], binaryKey, "".join(map(str, secretMessage)))

    print("Message bits inserted", bitsInserted)
    print("Samples used", samplesUsed)

    for i in range(0, len(stegoSamples)):
        stegoSamples[i] = int(stegoSamples[i], 2)

    print(
        "SNR",
        getSNR(originalCoverSamples[0:samplesUsed],
               stegoSamples[0:samplesUsed]))
    plotAmpDifference(originalCoverSamples, stegoSamples)


#testGA('Media/opera.wav', 'DDDDDDDDD')
def GA_encoding(coverSamples, secretMessage, key, frameRate, fileType):
    # Deepcopy for calculating the SNR
    originalCoverSamples = deepcopy(coverSamples[0])

    for i in range(0, len(coverSamples[0])):
        coverSamples[0][i] = "{0:016b}".format(coverSamples[0][i])

    secretMessage = "".join(map(str, secretMessage))

    # Provide first audio channel samples and message samples to encode
    currentTime = time.time()
    stegoSamples, samplesUsed, bitsInserted, capacityWarning = GA.insertMessage(
        coverSamples[0], key, "".join(map(str, secretMessage)), fileType)
    embeddingTime = time.time() - currentTime
    # Convert the binary audio samples to decimal samples
    for i in range(0, len(stegoSamples)):
        stegoSamples[i] = int(stegoSamples[i], 2)

        if (stegoSamples[i] < -32768):
            stegoSamples[i] = -32768

        if (stegoSamples[i] > 32767):
            stegoSamples[i] = 32767

    # Get the characteristics of the stego file
    SNR = RT.getSNR(originalCoverSamples[0:samplesUsed],
                    stegoSamples[0:samplesUsed])
    capacity = RT.getCapacity(secretMessage, samplesUsed, frameRate)
    spcc = RT.getSPCC(originalCoverSamples[0:samplesUsed],
                      stegoSamples[0:samplesUsed])
    mse = RT.getMSE(originalCoverSamples[0:samplesUsed],
                    stegoSamples[0:samplesUsed])
    prd = RT.getPRD(originalCoverSamples[0:samplesUsed],
                    stegoSamples[0:samplesUsed])
    psnr = RT.getPSNR(originalCoverSamples[0:samplesUsed],
                      stegoSamples[0:samplesUsed])

    return stegoSamples, capacity, SNR, capacityWarning, samplesUsed, spcc, mse, prd, psnr, embeddingTime
Beispiel #4
0
            binaryKey = fp.messageToBinary(keyString)
            binaryKey = binaryKey * int(
                (len(secretMessage) +
                 float(len(secretMessage)) / len(binaryKey)))

            originalCoverSamples = deepcopy(coverSamples[0])

            for i in range(0, len(coverSamples[0])):
                coverSamples[0][i] = "{0:016b}".format(coverSamples[0][i])

            secretMessage = "".join(map(str, secretMessage))

            # Provide first audio channel samples and message samples to encode
            start_time = time.time()
            stegoSamples, samplesUsed, bitsInserted, capacityWarning = GA.insertMessage(
                coverSamples[0], binaryKey, "".join(map(str, secretMessage)),
                ".txt")
            print((time.time() - start_time),
                  "seconds to execute embedding algorithm")

            # Extract secret message
            secretMessage, fileType = GA.extractMessage(
                stegoSamples, binaryKey)

            # Convert the binary audio samples to decimal samples
            for i in range(0, len(stegoSamples)):
                stegoSamples[i] = int(stegoSamples[i], 2)

            # Get the characteristics of the stego file
            print("Embedded " + str(bitsInserted) + " bits into " +
                  str(samplesUsed) + " samples.")
    print("##################################################")

    print(GA.determineFittest(sample, population))

    print("##################################################")
    print("#    Tesitng the insertion algorithm as in paper #")
    print("##################################################")
    samples = ['1001010001001100', '0101010111100111', '0000100011110001'] * 10

    print("Before insertion")
    for i in samples:
        print(i)

    message = '1010'
    key = '1001001110100000' * 2
    stego, samplesUsed, bitsInserted, capacityWarning = GA.insertMessage(
        samples, key, message, 'txt')
    print(stego)
    print("Message is:", message)
    print("key is:", key)
    print("")

    print("After insertion")
    for i in stego:
        print(i)

    print("##################################################")
    print("#   Tesitng the extraction algorithm as in paper #")
    print("##################################################")
    print(GA.extractMessage(stego, key))

    print("##################################################")