Exemplo n.º 1
0
def embed_LSB(carrierFile,payloadFile,outFile):
    """Embed a message in the carrier audio using modified LSB coding
   
    Returns audio data with the embedded payload
        
    Parameters:
        carrierFile - the name of the carrier audio file
        payloadFile - the name of the payload file
        outFile - the name of the file to which the package will be written
    """
    from amm import wavread,wavwrite
    _logInfo("Encoding...")
    
    # read in the carrier file
    samples,params = wavread(carrierFile,bSplit=False)
    samples = samples.tolist()
    sampleLength = len(samples)

    # Read the payload in and store it as a list of integers
    payload = None
    payloadData = None
    try:
        payload = open(payloadFile, 'rb')
        payloadData = bytesToInts(payload.read())
    except (IOerror) as err:
        _logError("Error reading from file '%s'" % payloadFile)
        raise err
    finally:
        if payload: payload.close()
    
    payloadDataLength = len(payloadData)
    payloadSizeData = bitsForInt(payloadDataLength,size=32)
    payloadSizeDataLength = len(payloadSizeData)

    _logDebug("Payload is %d bits" % payloadDataLength)
    _logDebug("That is %f of # of samples" % (float(payloadDataLength)/sampleLength))
    
    # Verify that the payload is reasonably sized
    if (payloadDataLength > (sampleLength - 32)):
        err = InvalidSize("Payload is too large.")
        _logError("Can't embed the payload into the carrier")
        raise err

    # Embed payload size into first 32 bits of package
    for i in xrange(32):
        if (samples[i] % 2 != payloadSizeData[i]):
            samples[i] += 1
    
    # Embed the payload in the carrier
    for i in xrange(payloadDataLength):
        if (samples[i+32] % 2 != payloadData[i]):
            samples[i+32] += 1

    # Write the package to file
    wavwrite(outFile,params,stream=samples)
    
    _logInfo("Success!")
Exemplo n.º 2
0
    xlabel(r'n (samples)')
    title(r'Step response')
    subplots_adjust(hspace=0.5)


# Read in audio file
samples, params = wavread("almostjungle1.wav", bSplit=False)
samples = samples.tolist()
sampleLength = len(samples)
sampleRate = params[2]

filter_order = 20
coefficients = signal.firwin(filter_order, cutoff=0.3, window="hamming")
#Frequency and phase response
#mfreqz(a)
#show()
#Impulse and step response
#figure(2)
#impz(a)
#show()

filtered_samples = []
# pass signal through filter
for i in range(sampleLength):
    products = []
    for j in range(filter_order):
        products.append(samples[i] * coefficients[j])
    filtered_samples.append(sum(products))

wavwrite("out.wav", params, stream=filtered_samples)
Exemplo n.º 3
0
       
    for i in xrange(0,len(left),windowSize):
        delay = zeroDelay if payloadData[i % payloadSize] == 0 else oneDelay
        stop = min(i+windowSize,min(len(left), len(right)))
        for j in xrange(i,stop):
            embedded_left[j] = (left[j] if j < delay 
                                else left[j] + ECHO_SCALE*left[j-delay])
            embedded_right[j] = (right[j] if j < delay 
                                 else right[j] + ECHO_SCALE*right[j-delay])
=======
    embedded_left = iFFTs(leftFFTs,timeStep)
    embedded_right = iFFTs(rightFFTs,timeStep)
>>>>>>> other
    
    _logInfo("Embedding complete. Writing file...")
    wavwrite(outFile,params,leftStream=embedded_left,rightStream=embedded_right)

def decode2(packageFile,outFile):
    from amm import wavread
    _logInfo("Decoding...")
    left,right,params = wavread(packageFile)
    sampleRate = params[2]
    sampleLength = params[3]*2

    windowSize = int(floor(sampleLength*0.001/2))
    _logDebug("window size is %d samples" % windowSize)
    
    payloadSizeBits = int(floor(sampleLength*0.001,2))
    _logDebug("First %d bits represent size of payload" % payloadSizeBits)

    
    subplots_adjust(hspace=0.5)


# Read in audio file
samples,params = wavread("almostjungle1.wav",bSplit=False)
samples = samples.tolist()
sampleLength = len(samples)
sampleRate = params[2]


filter_order = 20
coefficients = signal.firwin(filter_order, cutoff=0.3, window="hamming")
#Frequency and phase response
#mfreqz(a)
#show()
#Impulse and step response
#figure(2)
#impz(a)
#show()

filtered_samples = []
# pass signal through filter
for i in range(sampleLength):
    products = []
    for j in range(filter_order):
        products.append(samples[i] * coefficients[j])
    filtered_samples.append(sum(products))

wavwrite("out.wav",params,stream=filtered_samples)