def set_lowest_bit(value, bit_value): if bit_value == 0: if not is_even(value): value = value - 1 if bit_value==1: if is_even(value): value = value + 1 return value
I have a question in the first function why did you assign a value of 1 or 0 to each thing in the list then completely get rid of it and change all of the values to 0
the person we're commenting under rn had all the right code. thats all the code u need. what i sent above was the typo they made. just put this
def encode_pixel(cover_pixel, secret_pixel): # Implement this function # return a temporary value. Change this!! f_cover = [0,0,0] if secret_pixel[0]<=127: f_cover[0] = 1 else: f_cover[0] = 0 if secret_pixel[1]<=127: f_cover[1] = 1 else: f_cover[1] = 0 if secret_pixel[2]<=127: f_cover[2] = 1 else: f_cover[2] = 0 g_cover = [0,0,0] g_cover[0]= set_lowest_bit(cover_pixel[0], f_cover[0]) g_cover[1]= set_lowest_bit(cover_pixel[1], f_cover[1]) g_cover[2]= set_lowest_bit(cover_pixel[2], f_cover[2]) return g_cover ################################################################# # Extracts the RGB values for a secret pixel from the low bits # of the given cover pixel # # Input is an array of RGB values for a pixel. # # Returns a tuple of RGB values for the decoded pixel ################################################################# def decode_pixel(cover_pixel): # Implement this function # return a temporary value. Change this!! f_bit = [0,0,0] if get_lowest_bit(cover_pixel[0]) == 1: f_bit[0] = 225 else: f_bit[0] = 0 if get_lowest_bit(cover_pixel[1]) == 1: f_bit[1] = 225 else: f_bit[1] = 0 if get_lowest_bit(cover_pixel[2]) == 1: f_bit[2] = 225 else: f_bit[2] = 0 return f_bit #=========HELPER FUNCTIONS==========# # Returns true if the given value is even, false otherwise def is_even(value): # Implement this function # return a temporary value. Change this!! if value % 2 == 0: return True else: return False ################################################################# # # Given a number, return the lowest bit in the binary representation # of the number. # Returns either a 0 or a 1 # ################################################################# def get_lowest_bit(value): # Implement this function # return a temporary value. Change this!! lowest_bit = 0 if is_even(value) == True: lowest_bit = 1 else: lowest_bit = 0 return lowest_bit ################################################################# # # Given a number, return a new number with the same underlying bits # except the lowest bit is set to the given bit_value. # ################################################################# def set_lowest_bit(value, bit_value): # Implement this function if bit_value == 0: if not is_even(value): value = value - 1 if bit_value == 1: if is_even(value): value = value + 1 return value
3
u/HariNair06 Feb 08 '23
Its in python but don't worry your a big girl you can figure it out. It may look weird but thats how it should be.
def encode_pixel(cover_pixel, secret_pixel):
# Implement this function
# return a temporary value. Change this!!
new_cover = [0,0,0]
if secret_pixel[0] <= 127:
new_cover[0] = 1
else:
new_cover[0] = 0
if secret_pixel[1] <= 127:
new_cover[1] = 0
else:
new_cover[1] = 1
if secret_pixel[2] <= 127:
new_cover[2] = 0
else:
new_cover[2] = 1
newer_cover = [0,0,0]
newer_cover[0] = set_lowest_bit(cover_pixel[0], new_cover[0])
newer_cover[1] = set_lowest_bit(cover_pixel[1], new_cover[1])
newer_cover[2] = set_lowest_bit(cover_pixel[2], new_cover[2])
return newer_cover
def decode_pixel(cover_pixel):
new_bit = [0,0,0]
if get_lowest_bit(cover_pixel[0]) == 1:
new_bit[0] = 255
else:
new_bit[0] = 0
if get_lowest_bit(cover_pixel[1]) == 1:
new_bit[1] = 255
else:
new_bit[1] = 0
if get_lowest_bit(cover_pixel[2]) == 1:
new_bit[2] = 255
else:
new_bit[2] = 0
return new_bit
def is_even(value):
if value % 2 == 0:
return True
else:
return False
def get_lowest_bit(value):
lowest_bit = 0
if is_even(value) == True:
lowest_bit = 1
else:
lowest_bit = 0
return lowest_bit
def set_lowest_bit(value, bit_value):
if bit_value == 0:
if not is_even(value):
value = value - 1
if bit_value==1:
if is_even(value):
value = value + 1
return value
1
u/Ok_Agent3227 Nov 11 '22
Hey, I’ve been working on this assignment for awhile and have yet to get a clue on figuring it out. Did you ever figure out the code?