URI: 
       Add missing file - bitreich-bitmasquerade - Scripts for bitreich's new years eve bitmasqurade
   DIR Log
   DIR Files
   DIR Refs
       ---
   DIR commit c5e699275367669014b8fa015375893eb65d299a
   DIR parent 671752e65924e21870aa288dc51f7145dfcab61b
  HTML Author: Scarlett McAllister <no+reply@roygbyte.com>
       Date:   Sat, 23 Dec 2023 14:10:06 -0400
       
       Add missing file
       
       Diffstat:
         A atelier.dcgi                        |     129 +++++++++++++++++++++++++++++++
       
       1 file changed, 129 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/atelier.dcgi b/atelier.dcgi
       @@ -0,0 +1,129 @@
       +#!/usr/bin/env python
       +# coding=utf-8
       +
       +from functools import reduce
       +import re
       +import sys
       +
       +geomyidae_host = "server"
       +geomyidae_port = "port"
       +bitmask_selection = [ '010101010101', '110001100011', '001110011100',
       +                      '101010101010', '100000100001', '011111111110',
       +                      '000010010000', '100010001001', '010010001000',
       +                      '100110001110', '111111101111', '011000100010']
       +bitwise_selection = ['Flip', 'Set', 'Clear']
       +bitwise_operations = {'Flip' : lambda a, b: a ^ b,
       +                      'Set' : lambda a, b: a | b,
       +                      'Clear' : lambda a, b: a & b}
       +
       +def string_to_binary(s, bits):
       +    return ''.join([format(ord(c), '0{}b'.format(bits)) for c in s])
       +
       +def strip_char_to_ascii_range(s, start, end):
       +    range = [format(ord(a), 'x') for a in [start, end]]
       +    patt = r'[^\x{}-\x{}]+'.format(*range)
       +    return re.sub(patt, '', s)
       +
       +def strip_to_max_len(s):
       +    return s[:16]
       +
       +def print_nick_fail():
       +    print("Pardon, but I'll need your name")
       +
       +def print_step_1_template(nick):
       +    gph_menu_link = lambda s: \
       +        '[1|{}|atelier.dcgi?{} {}|{}|{}]'.format(s, nick, s,
       +                                                      geomyidae_host, geomyidae_port)
       +    gph_links = '\n'.join(map(gph_menu_link, bitmask_selection))
       +    with open('step_1.txt', 'r') as file:
       +        print(file.read().format(nick, gph_links))
       +
       +def print_step_2_template(nick, bitmask):
       +    gph_menu_link = lambda s: \
       +        '[1|{}|atelier.dcgi?{} {} {}|{}|{}]'.format(s, nick, bitmask, s,
       +                                                      geomyidae_host, geomyidae_port)
       +    gph_links = '\n'.join(map(gph_menu_link, bitwise_selection))
       +    with open('step_2.txt', 'r') as file:
       +        print(file.read().format(nick, gph_links))
       +
       +def print_completion(nick, bitmask, bitwise, mask):
       +    with open('step_complete.txt', 'r') as file:
       +        print(file.read().format(nick, bitmask, bitwise, mask))
       +
       +def make_mask(nick, bitmask, bitwise):
       +    bits = len(nick)
       +    binary_nick = string_to_binary(nick, bits)
       +    # print(binary_nick)
       +    def bit_picker(remaining, accm=""):
       +        if len(accm) == 0:
       +            # Recursion entry point: accumulate first element of
       +            # the list.
       +            return bit_picker(remaining[1:], remaining[0:1])
       +        if remaining == "":
       +            # Recursion exit point: return the accumulated elements.
       +            return accm
       +        # Main loop: return the current element that corresponds
       +        # with the current multiple of the remaining chars
       +        multiple = int(len(remaining)/bits)
       +        if (len(remaining) % bits) == multiple:
       +            accm = accm + remaining[0:1]
       +            # print(remaining)
       +            return bit_picker(remaining[1:], accm)
       +        return bit_picker(remaining[1:], accm)
       +    selected_bits = bit_picker(binary_nick)
       +    bitmask = bitmask[:len(selected_bits)]
       +    bin_1 = int(selected_bits, 2)
       +    bin_2 = int(bitmask, 2)
       +    return bin(bitwise_operations[bitwise](bin_2, bin_1))\
       +        [2:].zfill(len(selected_bits))
       +
       +def print_args_fail():
       +    print("Pardon, but something's not working.")
       +
       +def print_bitmask_fail():
       +    print("Pardon, but that bitmask isn't available.")
       +
       +def main(args):
       +    geomyidae_search = args[1]
       +    geomyidae_args = args[2].split(' ') # tab splitting
       +    if geomyidae_search:
       +        # Get the search result, which will be this
       +        # person's nick, and ask them to pick a bitmask from
       +        # the list printed out in the step 1 template.
       +        nick = strip_char_to_ascii_range(geomyidae_search, '!', '~')
       +        nick = strip_to_max_len(nick)
       +        if nick != '':
       +            print_step_1_template(nick)
       +        else:
       +            print_nick_fail()
       +        sys.exit()
       +    # Validate and clear up the input from the bitmask
       +    # selection.
       +    if len(geomyidae_args) < 2:
       +        print_args_fail()
       +        sys.exit()
       +    nick = strip_char_to_ascii_range(geomyidae_args[0], '!', '~')
       +    nick = strip_to_max_len(nick)
       +    bitmask = geomyidae_args[1]
       +    if nick == '':
       +        print_nick_fail()
       +        sys.exit()
       +    if bitmask not in bitmask_selection:
       +        print_bitmask_fail()
       +        sys.exit()
       +    if len(geomyidae_args) == 2:
       +        # Get the prson to choose their bitwise operation.
       +        print_step_2_template(nick, bitmask)
       +    else:        #
       +        bitwise = geomyidae_args[2]
       +        if bitwise not in bitwise_selection:
       +            print_bitmask_fail()
       +            sys.exit()
       +        # Finish up by making combining the nick, bitmask,
       +        # and bitwise operation.
       +        mask = make_mask(nick, bitmask, bitwise)
       +        print_completion(nick, bitmask[:len(nick)], bitwise, mask)
       +    sys.exit()
       +
       +if __name__ == "__main__":
       +    sys.exit(main(sys.argv))