Esempio n. 1
0
def decode_LSB(packageFile,outFile):
    """Decode the embedded message from the given package using modified LSB coding
        
    Returns the binary embedded message
        
    Parameters:
        packageFile - the name of the package audio file
        outFile - the name of the file to which the decoded payload will be written
    """
    from amm import wavread
    _logInfo("Decoding...")
    samples,params = wavread(packageFile,bSplit=False)
    
    # the first 32 bits encode the size of the payload
    payloadSizeChunk = samples[0:32]
    payloadSize = intForBits([i % 2 for i in payloadSizeChunk])
    _logDebug("Payload size = %d" % payloadSize)
    
    # check that the encoded payload size is not too large
    if (payloadSize > (len(samples) - 32)):
        err = InvalidSize("Specified payload size is too large")
        _logError("Invalid input for decoding")
        raise err
    
    payloadSegment = samples[32:32+payloadSize]
    
    payload = intsToBytes([i % 2 for i in payloadSegment])
    
    out = None
    try:
        out = io.open(outFile,'wb')
        out.write(bytearray(payload))
        out.flush()
    except IOError as err:
        _logError("Error writing out decoded data")
        raise err
    finally:
        if out: out.close()
    
    _logInfo("Success!")
Esempio n. 2
0
    ## DECODING IS NOT COMPLETE YET
=======
    from apm import FFTs,iFFTs

    leftFFTs = FFTs(left,WINDOWSIZE,timeStep)
    rightFFTs = FFTs(right,WINDOWSIZE,timeStep)

    decoded_data = []

    for i in range(len(leftFFTs)):
        mag1 = np.mean([abs(leftFFTs[i][f]) for f in FREQ1])
        mag0 = np.mean([abs(leftFFTs[i][f]) for f in FREQ0])
        bit = 0 if mag0 > mag1 else 1
        decoded_data.append(bit)

    payload = intsToBytes(decoded_data)

    out = None
    try:
        out = io.open(outFile,'wb')
        out.write(bytearray(payload))
        out.flush()
    except IOError as err:
        _logError("Error writing out decoded data")
        raise err
    finally:
        if out: out.close()

    _logInfo("Success!")
>>>>>>> other