LSB Least Significant Bit 最低有效位嵌入,这里就不赘述了。很多参考,原理一搜就出来了。
下面是相应的代码
首先,编写encode 和decode 代码,使用位操作
def LSB_encode(cover, m, k):
m = np.array(m, dtype = np.uint8)
cover = np.array(cover, dtype = np.uint8)
k = 2**k -1
mask1 = 255-k
mask2 = k
cover = np.bitwise_and(cover, mask1)
m = np.bitwise_and(m, mask2)
res = np.bitwise_or(cover,m)
return res
def LSB_decode(cover, k):
cover = np.array(cover, dtype = np.uint8)
mask1 = 2**k -1
m = np.bitwise_and(cover, mask1)
res = np.zeros(k, dtype = np.uint8)
m = str(bin(m))
m = m[2:].zfill(k)
for i in range(k):
res[i] = int(m[i