import copy
import random


def numList2blocks(l, n):
    """Take a list of integers(each between 0 and 127), and combines them
    into block size n using base 256. If len(L) % n != 0, use some random
    junk to fill L to make it."""
    # Note that ASCII printable characters range is 0x20 - 0x7E
    returnList = []
    toProcess = copy.copy(l)
    ''' copy message ascii list'''
    if len(toProcess) % n != 0:
        for i in range(0, n - len(toProcess) % n):
            ''' append rand str to list'''
            toProcess.append(random.randint(32, 126))
    toProcess[len(l)] = 0  # 0 after origin message list

    ''' generate int from ascii number list'''
    for i in range(0, len(toProcess), n):
        block = 0
        for j in range(0, n):
            block += toProcess[i + j] << (8 * (n - j - 1))
        returnList.append(block)
    return returnList