Looping issue in encryption program

I’m currently working on an encryption program that encodes text into RGB colour values for a PNG. Each file is 256 by 256, and therefore 65536 characters can be written into one image. However, If there are more than 65536 characters, I want it to create multiple files, however, I’m having trouble getting it to loop properly.

import itertools,turtle,time
import numpy as np
import scipy.misc as smp
from PIL import Image
import random

def draw_square(colour):
    t = turtle.Turtle()
    t.speed(0)
    t.fillcolor(colour)
    t.begin_fill()
    for i in range(4):
        t.forward(150)
        t.right(90)
    t.end_fill()
    time.sleep(.500)
    t.clear()
    
def hexer(inter):
    hexed = hex(inter).replace("0x","")

twotwofive = []
count = 0
while True:
    if count > 254:
        break
    else:
        twotwofive.append(count)
    count = count + 1
gb = list(itertools.product(twotwofive, repeat = 2))


def random_coords(array,count):
    coords = []
    while True:
        if len(coords) >= count:
            break
        else:
            while not array[random.randint(0,len(array) - 1)] in coords:
                coords.append(array[random.randint(0,len(array) - 1)] )
                if len(coords) >= count:
                    break
                else:
                    continue
    return coords

allowed_chars = [' ', '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', "'", '#', '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', '¬', '!', '"', '£', '$', '%', '^', '&', '*', '(', ')', '_', '+', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '@', '~', '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?']
def custom_chr(number):
    return allowed_chars[number - 1]
def custom_ord(character):
    return allowed_chars.index(character) + 1

signat = []

for dub in gb:
    signat.append(list(dub))

def gen_control_pixel(image_no):
    two_part = signat[int(image_no)]
    return [0,two_part[0],two_part[1]]

mode = input("Which mode do you require? [PIC/DEPIC] ")
while mode.lower() not in ["pic","depic"]:
    mode = input("Which mode do you require? [PIC/DEPIC] ")

if mode.lower() == "pic":
    name_of_file = input("What would you like to call the image? ")
    
    message = list(input("What's the message? "))
    ords = []

    for char in message:
        ords.append(custom_ord(char))

    channels = []

    counter = 0
    for num in ords:
        channels.append([num,signat[counter][0],signat[counter][1]])
        counter = counter + 1
        
    hex_codes = []
    for RGB in channels:
        hex_codes.append([RGB[0],RGB[1],RGB[2]])

    if len(hex_codes) > 65536:
        composite_list = [hex_codes[x:x + 65536] for x in range(0, len(hex_codes),65536)]
        run = len(composite_list)
        counter_a = 0
        counter = 0
        for part in composite_list:
            data = np.zeros( (256,256,3), dtype = np.uint8)
            ult_c = random_coords(gb,len(hex_codes))
            for colours in part:
                data[ult_c[counter][0],ult_c[counter][1]] = list(colours)
                counter = counter + 1
            img = Image.fromarray(data)
            counter_a = counter_a + 1
            img.save(name_of_file + "_" + str(counter_a) + ".png","PNG")
    else:
        counter = 0
        data = np.zeros( (256,256,3), dtype = np.uint8)
        ult_c = random_coords(gb,len(hex_codes))
        for colours in hex_codes:
            data[ult_c[counter][0],ult_c[counter][1]] = list(colours)
            counter = counter + 1
        img = Image.fromarray(data)
           
        img.save(name_of_file + ".png","PNG")
else:
    name_of_file = input("Which image do you wish to read? ")

    if ".png" in name_of_file:
        name_of_file.replace(".png","")
    else:
        nope = "nope"
        
    im = Image.open(name_of_file + ".png")
    pix = im.load()

    cols = []
    for coord in gb:
        cols.append(pix[coord[0],coord[1]])

    coloured = []
    for count in cols:
        if count[0] == 0:
            saved = [count[1],count[2]]
        else:
            coloured.append(count)

    twoer = []
    for reduce in coloured:
        my_sig = list([reduce[1],reduce[2]])
        the_order = signat.index(list(my_sig))
        twoer.append([reduce[0],the_order])
    done = sorted(twoer, key = lambda x: int(x[1]))
    
    the_output = ""
    for char in done:
        the_output = the_output + str(custom_chr(int(char[0])))
    print(the_output)

However, it throws up this error:

Which mode do you require? [PIC/DEPIC] PIC
What would you like to call the image? free_Code_Camp
What's the message? <<70000 Character String>>
Traceback (most recent call last):
  File "C:\***\***\***\***\***\***.py", line 79, in <module>
    channels.append([num,signat[counter][0],signat[counter][1]])
IndexError: list index out of range

I expect it to make a series of files, called free_Code_Camp_0.png, free_Code_Camp_1.png, etc. And for the decoder, I want to be able to input the ‘common name’ of the files, so ‘free_Code_Camp’, and have it go through all of the relevant files, and add the strings together. I’m also aware that this code isn’t very ‘Pythonic’ and if you have any tips, I will take them on board. I’ve never tried a project as ambitious as this, and I would appreciate any help. Thank you!