예제 #1
0
    def run():
        '''Display Monoalphabetic Subsitution Cipher Page'''

        # Load mode button
        mode.set_mode(monoalphabetic_subsitution_cipher_window,
                      monoalphabetic_subsitution_cipher_objects)

        # Set info button runclass
        monoalphabetic_subsitution_cipher_objects['info'].runclass = info.run
        monoalphabetic_subsitution_cipher_objects[
            'info'].runclass_parameter = page_name

        # Load screen
        pygame_ess.display.screen(monoalphabetic_subsitution_cipher_window,
                                  animate=True)
        monoalphabetic_subsitution_cipher.shuffle()
        logging.info('Loaded monoalphabetic subsitution cipher window.')

        while True:
            # Check for selection
            selection_result: dict = pygame_ess.event.selection(
                monoalphabetic_subsitution_cipher_window,
                monoalphabetic_subsitution_cipher_objects)

            # Check of mode button press
            mode.run(monoalphabetic_subsitution_cipher_window,
                     monoalphabetic_subsitution_cipher_objects)

            # Quit program
            if selection_result['action_result'] == 'quit' or pygame_ess.buffer(
                    monoalphabetic_subsitution_cipher_window):
                return 'quit'

            # Button press
            elif selection_result['object_type'] == 'button':
                # Go back to previous page
                if selection_result['action_result'] == 'back':
                    return True
                    # Shuffle the key
                elif selection_result['action_result'] == 'shuffle':
                    monoalphabetic_subsitution_cipher.shuffle()

            # Textfield updated
            elif selection_result['object_type'] == 'textfield':
                # encrypt to ciphertext
                if mode.current_mode == 'encrypt':
                    monoalphabetic_subsitution_cipher.encrypt()
                    # decrypt to plaintext
                elif mode.current_mode == 'decrypt':
                    monoalphabetic_subsitution_cipher.decrypt()
예제 #2
0
    def run(cipher_type: str = 'affine_cipher'):
        '''Display cryptography home page'''

        # Ensure cipher_type exist
        if cipher_type not in info_screen_data.keys():
            logging.error(
                '[{}] No such cipher type for the info screen.'.format(
                    info_window.name))
            return True

        # Set correct info screen
        # Set height
        info_window.frame.by = 0
        info_window.frame.h = int(info_screen_data[cipher_type]['height'] *
                                  config.scale_w())
        # Set button position
        info_objects['learn_more'].frame.by = int(
            (info_screen_data[cipher_type]['height'] - 123) * config.scale_w())
        info_objects['learn_more'].frame.iy = int(
            (info_screen_data[cipher_type]['height'] - 123) * config.scale_w())
        info_objects['try_now'].frame.by = int(
            (info_screen_data[cipher_type]['height'] - 123) * config.scale_w())
        info_objects['try_now'].frame.iy = int(
            (info_screen_data[cipher_type]['height'] - 123) * config.scale_w())

        # Load screen
        pygame_ess.load.objects(info_window.surface, info_objects,
                                [cipher_type])
        pygame_ess.display.screen(info_window, animate=True)

        while True:
            # Check for selection
            selection_result: dict = pygame_ess.event.selection(
                info_window, info_objects)

            # Quit program
            if selection_result['action_result'] == 'quit' or pygame_ess.buffer(
                    info_window):
                return 'quit'

            # Close info window
            elif selection_result['action_result'] == 'back':
                return True

            # Open learn more URL
            elif selection_result['action_result'] == 'learn_more':
                webbrowser.open(info_screen_data[cipher_type]['link'])
예제 #3
0
    def run():
        '''Display Credits page'''

        # Load the screen
        pygame_ess.display.screen(credits_window)
        logging.info('Loaded credits window.')

        while True:
            # Check for selection
            selection_result:dict = pygame_ess.event.selection(credits_window, credits_objects)

            # Quit program
            if selection_result['action_result'] == 'quit' or pygame_ess.buffer(credits_window): 
                return 'quit'

            # Button press
            elif selection_result['object_type'] == 'button':
                # Go back to previous page
                if selection_result['action_result'] == 'back': return True
예제 #4
0
    def run():
        '''Display Caesar Cipher Page'''

        # Load mode button
        mode.set_mode(caesar_cipher_window, caesar_cipher_objects)

        # Set info button runclass
        caesar_cipher_objects['info'].runclass = info.run
        caesar_cipher_objects['info'].runclass_parameter = page_name

        # Load the screen
        pygame_ess.display.screen(caesar_cipher_window, animate=True)
        caesar_cipher.encrypt()
        logging.info('Loaded caesar cipher window.')

        while True:
            # Check for selection
            selection_result: dict = pygame_ess.event.selection(
                caesar_cipher_window, caesar_cipher_objects)

            # Check of mode button press
            mode.run(caesar_cipher_window, caesar_cipher_objects)

            # Quit program
            if selection_result['action_result'] == 'quit' or pygame_ess.buffer(
                    caesar_cipher_window):
                return 'quit'

            # Button press
            elif selection_result['object_type'] == 'button':
                # Go back to previous page
                if selection_result['action_result'] == 'back': return True

            # Textfield updated
            elif selection_result['object_type'] == 'textfield':
                # encrypt to ciphertext
                if mode.current_mode == 'encrypt':
                    caesar_cipher.encrypt()
                    # decrypt to plaintext
                elif mode.current_mode == 'decrypt':
                    caesar_cipher.decrypt()
예제 #5
0
    def run(invalid_message: str = 'Oh no! Your input is invalid!'):
        '''Display cryptography home page'''

        # Set message
        invalid_input_objects['message'].meta.text = invalid_message
        # Load the screen
        pygame_ess.display.object(invalid_input_window,
                                  invalid_input_objects['message'])
        logging.info('Loaded invalid input window.')

        while True:
            # Check for selection
            selection_result: dict = pygame_ess.event.selection(
                invalid_input_window,
                invalid_input_objects,
                direct_to_screen=True)

            # Quit program
            if selection_result['action_result'] == 'quit' or pygame_ess.buffer(
                    invalid_input_window):
                return 'quit'

            # Dismiss alert
            if selection_result['action_result'] == 'back': return True