def setPixelAlphasFromIntsRandom(image, ints):
    """
    Encrypt the message into the image's alpha values starting in a random order.
    """
    cleanImage(image)
    pixelData = list(image.getdata())

    length = len(ints)
    rand = int(len(pixelData) / length)

    position = 0

    randomPosition = []
    for i in range(length):
        value = random.randint(position, (rand - 1) + position)
        randomPosition.append(value)
        position += value - position

    for x in range(len(ints)):
        r = 0
        g = 0
        b = 0
        a = 0
        try:
            r, g, b, a = pixelData[randomPosition[x]]
        except:
            r, g, b = pixelData[randomPosition[x]]
            a = 255
        color = Color(r, g, b, a)
        color.alpha = ints[x]
        pixelData[randomPosition[x]] = color.getColor()
    image.putdata(pixelData)
def setPixelAlphasFromInts(image, ints):
    """
    Encrypt the message into the image's alpha values starting in top right.
    """
    cleanImage(image)
    pixelData = list(image.getdata())
    for x in range(len(ints)):
        r = 0
        g = 0
        b = 0
        a = 0
        try:
            r, g, b, a = pixelData[x]
        except:
            r, g, b = pixelData[x]
            a = 255
        color = Color(r, g, b, a)
        color.alpha = ints[x]
        pixelData[x] = color.getColor()
    image.putdata(pixelData)
def cleanImage(image):
    """
    Erases a previously encrypted message in an image by resetting all of the alpha values.
    """
    pixelData = list(image.getdata())
    w, h = image.size
    size = w * h
    for x in range(size):
        r = 0
        g = 0
        b = 0
        a = 0
        try:
            r, g, b, a = pixelData[x]
        except:
            r, g, b = pixelData[x]
            a = 255
        a = 255
        color = Color(r, g, b, a)
        color.alpha = 255
        pixelData[x] = color.getColor()
    image.putdata(pixelData)