#!/usr/bin/env python3

from itertools import product


def main():
    target_byte = 0xF1
    # copied from https://github.com/Exim/exim/blob/286b9d5fa4344de72fe6575fa089237fd7dbb56f/src/src/base64.c
    dec_64_table = [
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        62,
        255,
        255,
        255,
        63,
        52,
        53,
        54,
        55,
        56,
        57,
        58,
        59,
        60,
        61,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        0,
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        11,
        12,
        13,
        14,
        15,
        16,
        17,
        18,
        19,
        20,
        21,
        22,
        23,
        24,
        25,
        255,
        255,
        255,
        255,
        255,
        255,
        26,
        27,
        28,
        29,
        30,
        31,
        32,
        33,
        34,
        35,
        36,
        37,
        38,
        39,
        40,
        41,
        42,
        43,
        44,
        45,
        46,
        47,
        48,
        49,
        50,
        51,
        255,
        255,
        255,
        255,
        255,
    ]

    dec_64_table = [i for i in dec_64_table if i != 255]
    enc_64_table = [
        c for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    ]

    assert len(dec_64_table) == len(enc_64_table)

    x_table = [x >> 2 for x in dec_64_table]
    y_table = [y << 4 for y in dec_64_table]

    all_combinations = set()

    for x, y in product(x_table, y_table):
        x_or_y = x | y
        if hex(x_or_y)[-2:] == hex(target_byte)[2:]:
            mask_x = [_x == x for _x in x_table]
            mask_y = [_y == y for _y in y_table]

            valid_x = [_x for _x, c in zip(dec_64_table, mask_x) if c]
            valid_y = [_y for _y, c in zip(dec_64_table, mask_y) if c]

            # print(valid_x, valid_y)
            #
            # print("valid characters for x:")
            # print(", ".join(enc_64_table[idx] for idx in valid_x))
            #
            # print("valid characters for y:")
            # print(", ".join(enc_64_table[idx] for idx in valid_y))

            all_combinations.update(
                set(
                    [
                        f"{enc_64_table[y]}{enc_64_table[x]}"
                        for y, x in product(valid_y, valid_x)
                    ]
                )
            )

    print(all_combinations)


if __name__ == "__main__":
    main()

1235757523c625c9353da08db9b6446fbbaa1637
<mask token>

<mask token>


def main():
    target_byte = 241
    dec_64_table = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
        255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
        255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
        255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63, 52, 53, 54, 55,
        56, 57, 58, 59, 60, 61, 255, 255, 255, 255, 255, 255, 255, 0, 1, 2,
        3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
        22, 23, 24, 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 
        31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
        48, 49, 50, 51, 255, 255, 255, 255, 255]
    dec_64_table = [i for i in dec_64_table if i != 255]
    enc_64_table = [c for c in
        'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/']
    assert len(dec_64_table) == len(enc_64_table)
    x_table = [(x >> 2) for x in dec_64_table]
    y_table = [(y << 4) for y in dec_64_table]
    all_combinations = set()
    for x, y in product(x_table, y_table):
        x_or_y = x | y
        if hex(x_or_y)[-2:] == hex(target_byte)[2:]:
            mask_x = [(_x == x) for _x in x_table]
            mask_y = [(_y == y) for _y in y_table]
            valid_x = [_x for _x, c in zip(dec_64_table, mask_x) if c]
            valid_y = [_y for _y, c in zip(dec_64_table, mask_y) if c]
            all_combinations.update(set([
                f'{enc_64_table[y]}{enc_64_table[x]}' for y, x in product(
                valid_y, valid_x)]))
    print(all_combinations)


<mask token>

<mask token>


def main():
    target_byte = 241
    dec_64_table = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
        255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
        255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
        255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63, 52, 53, 54, 55,
        56, 57, 58, 59, 60, 61, 255, 255, 255, 255, 255, 255, 255, 0, 1, 2,
        3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
        22, 23, 24, 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 
        31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
        48, 49, 50, 51, 255, 255, 255, 255, 255]
    dec_64_table = [i for i in dec_64_table if i != 255]
    enc_64_table = [c for c in
        'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/']
    assert len(dec_64_table) == len(enc_64_table)
    x_table = [(x >> 2) for x in dec_64_table]
    y_table = [(y << 4) for y in dec_64_table]
    all_combinations = set()
    for x, y in product(x_table, y_table):
        x_or_y = x | y
        if hex(x_or_y)[-2:] == hex(target_byte)[2:]:
            mask_x = [(_x == x) for _x in x_table]
            mask_y = [(_y == y) for _y in y_table]
            valid_x = [_x for _x, c in zip(dec_64_table, mask_x) if c]
            valid_y = [_y for _y, c in zip(dec_64_table, mask_y) if c]
            all_combinations.update(set([
                f'{enc_64_table[y]}{enc_64_table[x]}' for y, x in product(
                valid_y, valid_x)]))
    print(all_combinations)


if __name__ == '__main__':
    main()

from itertools import product


def main():
    target_byte = 241
    dec_64_table = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
        255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
        255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
        255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63, 52, 53, 54, 55,
        56, 57, 58, 59, 60, 61, 255, 255, 255, 255, 255, 255, 255, 0, 1, 2,
        3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
        22, 23, 24, 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 
        31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
        48, 49, 50, 51, 255, 255, 255, 255, 255]
    dec_64_table = [i for i in dec_64_table if i != 255]
    enc_64_table = [c for c in
        'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/']
    assert len(dec_64_table) == len(enc_64_table)
    x_table = [(x >> 2) for x in dec_64_table]
    y_table = [(y << 4) for y in dec_64_table]
    all_combinations = set()
    for x, y in product(x_table, y_table):
        x_or_y = x | y
        if hex(x_or_y)[-2:] == hex(target_byte)[2:]:
            mask_x = [(_x == x) for _x in x_table]
            mask_y = [(_y == y) for _y in y_table]
            valid_x = [_x for _x, c in zip(dec_64_table, mask_x) if c]
            valid_y = [_y for _y, c in zip(dec_64_table, mask_y) if c]
            all_combinations.update(set([
                f'{enc_64_table[y]}{enc_64_table[x]}' for y, x in product(
                valid_y, valid_x)]))
    print(all_combinations)


if __name__ == '__main__':
    main()

#!/usr/bin/env python3

from itertools import product


def main():
    target_byte = 0xF1
    # copied from https://github.com/Exim/exim/blob/286b9d5fa4344de72fe6575fa089237fd7dbb56f/src/src/base64.c
    dec_64_table = [
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        62,
        255,
        255,
        255,
        63,
        52,
        53,
        54,
        55,
        56,
        57,
        58,
        59,
        60,
        61,
        255,
        255,
        255,
        255,
        255,
        255,
        255,
        0,
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        11,
        12,
        13,
        14,
        15,
        16,
        17,
        18,
        19,
        20,
        21,
        22,
        23,
        24,
        25,
        255,
        255,
        255,
        255,
        255,
        255,
        26,
        27,
        28,
        29,
        30,
        31,
        32,
        33,
        34,
        35,
        36,
        37,
        38,
        39,
        40,
        41,
        42,
        43,
        44,
        45,
        46,
        47,
        48,
        49,
        50,
        51,
        255,
        255,
        255,
        255,
        255,
    ]

    dec_64_table = [i for i in dec_64_table if i != 255]
    enc_64_table = [
        c for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    ]

    assert len(dec_64_table) == len(enc_64_table)

    x_table = [x >> 2 for x in dec_64_table]
    y_table = [y << 4 for y in dec_64_table]

    all_combinations = set()

    for x, y in product(x_table, y_table):
        x_or_y = x | y
        if hex(x_or_y)[-2:] == hex(target_byte)[2:]:
            mask_x = [_x == x for _x in x_table]
            mask_y = [_y == y for _y in y_table]

            valid_x = [_x for _x, c in zip(dec_64_table, mask_x) if c]
            valid_y = [_y for _y, c in zip(dec_64_table, mask_y) if c]

            # print(valid_x, valid_y)
            #
            # print("valid characters for x:")
            # print(", ".join(enc_64_table[idx] for idx in valid_x))
            #
            # print("valid characters for y:")
            # print(", ".join(enc_64_table[idx] for idx in valid_y))

            all_combinations.update(
                set(
                    [
                        f"{enc_64_table[y]}{enc_64_table[x]}"
                        for y, x in product(valid_y, valid_x)
                    ]
                )
            )

    print(all_combinations)


if __name__ == "__main__":
    main()
