最近在学习相关的解决知识,搜索到这个题目,尝试了一下。原本以为需要比较深的数学知识解决mod(),还好手工推演一下也可以解决。
[Python] 纯文本查看 复制代码 from PIL import Image
def enc():
im = Image.open('1x8.png')
new = Image.new('RGB',(255,255),(255,255,255))
for y in range(255):
for x in range(255):
fd = im.getpixel((x,y))
re = (fd+x+y) % 68
xin = Image.new('RGB',(1,1),(re,re,re))
new.paste(xin,(x,y))
new.save('enc.png')
def umod(v):
while v < 0:
v += 68
if v == 51:
r = 255
else:
r = 0
return r
def dec():
im = Image.open('enc.png')
new = Image.new('L',(255,255))
for y in range(255):
for x in range(255):
re = im.getpixel((x,y))[0]
fd = umod(re-x-y)
new.putpixel((x,y),fd)
new.save('new.png')
|