We have ab mod c = d where we know b (key), c (251), and d (encrypted pixel value). Multiplying by the modular inverse of b gets us: a mod c = d * b^-1 mod c

Calculate this for every pixel in the image with a script, and you get an image that contains the flag.

import numpy as npfrom PIL import Imagefrom Crypto.Util.number import inverseenc_image = Image.open('enc.png')img = np.array(enc_image)a, b, c = img.shapekey = [41,37,23]for x inrange(0, a):for y inrange(0, b): pixel = img[x, y]for i inrange(0, 3): pixel[i]=inverse(key[i], 251)* pixel[i]%251 img[x, y]= pixelflag = Image.fromarray(img)flag.save('flag.png')