EntityScript

Draft 1.2:
Index


core_hash





"""
Copyright (C) 2020 New Entity Operations Inc.

ALL RIGHTS RESERVED

core_hash provides hash routines to use within C.ORE

Import the hashing lookup, storage, and inspection tool to understand entities

Usage:

#class Message:
#    # More fun with hashlib
#    #COPYRIGHT RYAN MCKENNA ALL RIGHTS RESERVED
#    import hashlib
#    vault_1 = sha512()
#    vault_1
#    # 
#    encryptor = b'adsfsadfdsfadsf342sf'
#    message_cryptor = b'Hey there jimbo james'
#    vault_1.update(encryptor + message_cryptor)
#    vault_1
#    # 
#    sent = vault_1.hexdigest()
#    sent
#    #'3cdb9e4f879fd818e3148e60***...ahah'
#    # 318ff5567'
#    received = sent
#    received
#    # '3cdb9e4f879fd8***...dhs'
#    # 318ff5567'
#    vault_1
#    # 
#    print(vault_1)
#    # 
#    message_list = []
#    message_list.append(vault_1)
#    message_list
#    # []
#    message_list.append({'message_1': sent})
#    message_list
#    # [, {'message_1': '3cdb9***...3h'}]
#    zed = vault_1.update(bytes(input(), 'utf-8') + message_cryptor)
#    zed
#    vault_1
#    # 
#    print(zed)
#    # None
#    dir(vault_1)
#    # ...
#    # , 'block_size', 'copy', 'digest', 'digest_size', 'hexdigest', 'name', 'update']
#    vault_1.name
#    # 'sha512'
#    vault_1.update
#    # 
#    vault_1.hexdigest
#    # 
#    print(vault_1.hexdigest)
#    # 
#    vault_1.__hash__
#    # 
#
#    ###################################################
#    import hashlib
#    vault_1 = sha512()
#    vault_1
#    # 
#    encryptor = b'adsfsadfdsfadsf342sf'
#    message_cryptor = b'Hey there jimbo james'
#    vault_1.update(encryptor + message_cryptor)
#    vault_1
#    # 
#    sent = vault_1.hexdigest()
#    sent
#    # '3cdb9e4f87***...ab'
#    # 318ff5567'
#    received = sent
#    received
#    #'3cdb9e4f879fd818***...6cf91'
#    #318ff5567'
#    ##################################################################
#    import hashlib
#    _password = b"Hnshdlepshanehsop"
#    stored_pass = sha512(_password)
#    stored_pass.hexdigest()
#    # 'e00c566d8b59ab9de***...a'
#    # 79b49964a'
#    hash_stored = stored_pass.hexdigest()
#    hash_stored
#    # 'e00c566d8b59***...a'
#    _message_1 = b"Hey what's going on over there?"
#    _sent_message_1 = sha512(_message_1)
#    _sent_message_1_sent = _sent_message_1.hexdigest()
#    _sent_message_1_sent
#    # '145ce8bb47fd7d9448c0***...f'

# Import random library as a baseline randomizer.
# You should vet your own randomizer before relying on it


# Usage:::
# >>> import core_hash
# >>> core_hash.Slug.HASHED_SLUG
# >>> core_hash.Operator()
# Enter the extension type do you want to index: jpg
# Enter the file you need a hash for:
# /full/path/to/image/image.jpg
# ...

"""
# Import the required built-in libraries
from hashlib import (
    md5, sha1, sha256, sha512
)
from pathlib import (
    Path,
)
from random import (
    randint,
)
# Imports: Custom
from core_middlelayer import (
    DIRDATA, DIRPHOTO,
    ENTITYMANIFEST, EXTALLOWED, HASHDIR, 
    SEARCHPARAMS, SLUGHASH,
    THREADMEDIADIR, THREADDEHASH
)

class Slug:
    """
    Hold the 'HASHED_SLUG' in a 'hollow_class' and repopulate it later in the
    program.
    """
    HASHED_SLUG = SLUGHASH

## Operator OverClass
def Operator():
    # Slug1: Define your operation paths
    thread_directory = str(THREADMEDIADIR)
    thread_dehash = str(THREADDEHASH)
    dir_photo_search = str(DIRPHOTO)
    # Assembler: slug1,slug2,...,slugn
    thread_photo = thread_directory+thread_dehash+dir_photo_search

    # Entity: In-transit Folders (ITFs)
    data_dir = DIRDATA
    file_entity_manifest = data_dir+ENTITYMANIFEST
    file_hash = data_dir+HASHDIR

    # Base permissions
    file_write = 'w'
    file_read_bytes = 'rb'

    # Define lib-operators
    allowed_operators = EXTALLOWED

    # Define search patterns
    pattern = SEARCHPARAMS

    # Static export operators
    p = Path(thread_photo)
    # p1 = Path(slug)

    # Init input setup: First Active Element (FAE) interaction model
    ext_get = input("Enter the extension type do you want to index: ")

    # Operations
    def program_logic():
        """
        program_logic() will run when logic() runs
        """
        filename_hash = input(
            "Enter the file you need a hash for: "
        )
        try:
            with open(filename_hash, file_read_bytes) as h:
                bytes = h.read()
                hash_value_md5 = md5(bytes).hexdigest()
                hash_value_sha1 = sha1(bytes).hexdigest()
                hash_value_sha256 = sha256(bytes).hexdigest()
                hash_value_sha512= sha512(bytes).hexdigest()
                #print('MD5: ',hash_value_md5)
                #print('SHA256: ',hash_value_sha256)
                #print('SHA512: ',hash_value_sha512)
                md5_output = ('MD5: ', hash_value_md5)
                sha1_output = ('SHA1: ', hash_value_sha1)
                sha256_output = ('SHA256: ', hash_value_sha256)
                sha512_output = ('SHA512: ', hash_value_sha512)
                o = open(file_hash, file_write)
                output = 'File Inspector: '+\
                filename_hash,
                md5_output, sha1_output, sha256_output, sha512_output
                o.write(str(output))
                o.close()
                with open (file_hash, file_read_bytes) as reader:
                    Slug.HASHED_SLUG = reader.read()
                    print('\n\n----- HASHED CONTENT -----\n\n')
                    print(Slug.HASHED_SLUG)
                reader.close()
            h.close()
        except:
            FileNotFoundError
            print('File not found, try again.')

    # Path logic
    def logic():
        """
        logic() will run when sanitize() conludes running
        """
        logic_bin = []

        with open(file_entity_manifest, 'at') as f:
            for key, value in z.items():
                logic_bin.append(str(value)+"\n")
            #f.write(logic_bin)
            logic_bin.sort()
            for i in logic_bin:
                f.write(i)
        # fstringVersion = str(z)
        # f.write(fstringVersion)
        # for i in fstringVersion:
        # f.write(i+"\n")

        f.close()

        # Printed Version
        # for i in enumerate(z.values()):
        #   print(i,'\n')
        program_logic()

    # Sanitize the function 'injection' parameters
    def sanitize():
        """
        sanitize() runs when 'ext_get' not in 'allowed_operators' fails 

        (Conditions at runtime)
        """
        inject_sanitized = pattern+ext_get
        # 'ext' always takes a 'inject_sanitized' string as a desired type
        # in this case, the desired type is 'str'
        ext = str(inject_sanitized)
        global z
        z = {key: value for (key, value) in enumerate(p.glob(ext))}
        logic()

        if ext_get not in allowed_operators:
            """
            Run the routine to rule out disallowed types by default, if True, move to 
            else:
                block_executor()
            """
            print("Please provide an allowed type")
            print("Allowed Types: ")
            for i in allowed_operators:
                print(i)
            else:
                sanitize()

    # RunTest: Display items from 'dir_photo_search'
    # print('\n')
    # print('----- Sanity Test: -----')
    # print('----- 1st Item -----')
    # print(z[0],'\n')
    # print('----- 100th Item -----')
    # print(z[100],'\n')
    # print('----- 1000th Item -----')
    # print(z[1000],'\n')

def setup_universe():
    #*********************************************#
    # START: STEP 3 - BUILD VIRTUAL THREADPOOL    #
    #*********************************************#
    alien_limit = 50
    global alien_table
    alien_table = [[] for _ in range(alien_limit)]
    print(
        "---------- START: STEP 3 - BUILD VIRTUAL THREAD POOL OF: X ----------")
    print(alien_table)
    base_function_alien = alien_limit - 1
    print(base_function_alien)
    print(
        "---------- STOP: STEP 3 - BUILD VIRTUAL THREAD POOL OF: X ----------\n"
    )
    #********************************************#
    # STOP: STEP 3 - BUILD VIRTUAL THREADPOOL    #
    #********************************************#

setup_universe()

class AlienCoverUp:
    """
    Wipe the alien hash. reestablish the universe
    """
    def activated():
        alien_table.clear()
        setup_universe()

class AlienHash:
    """
    Usage:
    # This is the default run that will go to alien_hash witha random value
    >>> core_hash.AlienHashInsert.insert(
     core_hash.alien_table, 0, ('NEOD', 'Thomas Anderman', '10000000'
    ))
    # This is the member defined input value and will provide a I/O hash
    >>> core_hash.AlienHashInsert.insert(
     core_hash.alien_table, 33, ('NEOD', 'Thomas Anderman', '10000000'
    ))
    >>> core_hash.alien_table
    """
    def alien_hash(x):
        """
        Return the 'alien_hash' value, providing the insert_key
        """
        return(round(float(x/4+20-1)))

    def get_hash(given_value=0):
        """
        If no value is given, the default value will be 0 and run
        the default 'random_limit' function
        """
        if given_value==0:
            random_limit = randint(1, alien_limit)
            x = random_limit
            return(AlienHash.alien_hash(x))
        else:
            x = given_value
            return(AlienHash.alien_hash(x))

    class Failure:
        def failed_value():
            # return(round(alien_limit / randint(1, alien_limit)))
            # return(round(alien_limit / 2))
            return(AlienHash.alien_hash(2))

class AlienHashInsert:
    """
    'AlienHashInsert' is a prototype for linking unique hashes together in C.ORE

    You can replace Failure.def_value() and AlienHash.alien_hash(x)
    with different extending functions
    Alien hash: The Game Example

    Find the alien this way...

    Insert the standard Tuple with a key

    """
    class DefaultPlayer:
        """
        player_id must be in range of matrix blocks
        """
        player_id = 20
        AliasName = 'The Hidden but True Alien'
        Name = 'John Smith'
        Skill = 71092

        global DP

    # DefaultPlayer short function
    DP = DefaultPlayer

    # Active Game Spaces in matrix format
    def insert(alien_table, key, values):
        try:
            alien_table[AlienHash.get_hash(given_value=key)].append(values)
        except:
            IndexError
            print("Index error starting backup.")
            key = AlienHash.Failure.failed_value()
            print(key)
            alien_table[AlienHash.get_hash(given_value=key)].append(values)

    def delete(alien_table, key, values):
        alien_table[AlienHash.get_hash(given_value=key)].remove(values)



Return HOME