def extractor(line,position):
    bit_str = ''
    for pixel in line:
        for intensity in pixel:
            bit_str += bits.get_bit(intensity,position)
    line_str = bits.bits_to_message(bit_str)
    line_n = int(line_str)
    return line_n
def decode(image):
    """
    Takes an image as its argument and returns a string of ASCII characters
    as its result.
    Decoding process:
    - Iterate over each intensity value in each pixel and do the following:
        - Convert intensity value of image to binary
        - Index LSB of intensity value and append it to a growing list
        of bits
    - After this operation, a string of bits is obtained, a part of which 
    (or all of it) is the bitstream of the coded message. 
    - Decode the entire string of bits using the bit_to_message function
    
    Inputs:
        image: a two-dimensional list of pixels, in zero-based row-major 
               order. Each pixel is a three element tuple of integers in the 
               range [0,255]
    
    Result:
        A string of ASCII characters, decoded from image using steganography 
        scheme described above.
    
    Examples:
        >>> decode(encode(test_image,''))
        ''
        >>> decode(encode(test_image,'hi'))
        'hi'
        >>> decode(encode(test_image,'hello'))
        'he'
    
    """
    bitstream = ''
    for row in image:
        for pixel in row:
            for intensity in pixel:
                # Use get_bit function from bits.py library
                # to select the LSB of each intensity value
                bitstream += bits.get_bit(intensity,0)
    # Decode message using bits_to_message function
    message = bits.bits_to_message(bitstream)
    return message  
def decode_ext(image, num_bits):
    """
    Very slight change from original decode function;
    addition of extra nested 'for' loop allows iteration over
    one intensity value to extract multiple code bits, as 
    determined by num_bits input
    """
    if not(0 < num_bits <= 8):
        print ('Number of bits must be an integer between 1 and 8\
 inclusive')
        return None 
    bitstream = ''
    for row in image:
        for pixel in row:
            for intensity in pixel:
                # Extra 'for' loop so more than one bit can be
                # selected from each intensity value 
                for pos in range(num_bits):
                    bitstream += bits.get_bit(intensity,pos)
    message = bits.bits_to_message(bitstream)
    return message  
def round_trip(message):
    """
    - Used to test bits_to_message and message_to_bits functions
    - Should always return True
    """
    return bits.bits_to_message(bits.message_to_bits(message)) == message