





from __future__ import annotations

import random
import string




class 			_lowerCamelCase	:



      """simple docstring"""






      def __init__(	self			,  UpperCAmelCase = None				)    ->				None:






        '''simple docstring'''






        __snake_case				:			Dict            =    passcode or self.__passcode_creator()
        __snake_case				:			Optional[Any]            =    self.__make_key_list()
        __snake_case				:			int            =    self.__make_shift_key()







      def __str__(	self				)    ->				str:






        '''simple docstring'''






        return "".join(self.__passcode				)







      def   UpperCAmelCase						(	self			,  UpperCAmelCase				)    ->				list[int]:






        '''simple docstring'''






        for i in range(1			,  len(UpperCAmelCase				)			,  2				):
          iterlist[i] *= -1
        return iterlist







      def   UpperCAmelCase						(	self				)    ->				list[str]:






        '''simple docstring'''






        __snake_case				:			Tuple            =    string.ascii_letters + string.digits
        __snake_case				:			Optional[int]            =    [random.choice(UpperCAmelCase				) for _ in range(random.randint(10			,  20				)				)]
        return password







      def   UpperCAmelCase						(	self				)    ->				list[str]:






        '''simple docstring'''






        __snake_case				:			Union[str, Any]            =    (
            string.ascii_letters + string.digits + string.punctuation + " \t\n"
        )

        __snake_case				:			Optional[int]            =    []

        # creates points known as breakpoints to break the key_list_options at those
        # points and pivot each substring
        __snake_case				:			Any            =    sorted(set(self.__passcode				)				)
        __snake_case				:			list[str]            =    []

        # algorithm for creating a new shuffled list, keys_l, out of key_list_options
        for i in key_list_options:
          temp_list.extend(UpperCAmelCase				)

          # checking breakpoints at which to pivot temporary sublist and add it into
          # keys_l
          if i in breakpoints or i == key_list_options[-1]:
            keys_l.extend(temp_list[::-1]				)
            temp_list.clear()

        # returning a shuffled keys_l to prevent brute force guessing of shift key
        return keys_l







      def   UpperCAmelCase						(	self				)    ->				int:






        '''simple docstring'''






        __snake_case				:			Optional[int]            =    sum(self.__neg_pos([ord(UpperCAmelCase				) for x in self.__passcode]				)				)
        return num if num > 0 else len(self.__passcode				)







      def   UpperCAmelCase						(	self			,  UpperCAmelCase				)    ->				str:






        '''simple docstring'''






        __snake_case				:			str            =    ""

        # decoding shift like Caesar cipher algorithm implementing negative shift or
        # reverse shift or left shift
        for i in encoded_message:
          __snake_case				:			Tuple            =    self.__key_list.index(UpperCAmelCase				)
          decoded_message += self.__key_list[
              (position - self.__shift_key) % -len(self.__key_list				)
          ]

        return decoded_message







      def   UpperCAmelCase						(	self			,  UpperCAmelCase				)    ->				str:






        '''simple docstring'''






        __snake_case				:			List[Any]            =    ""

        # encoding shift like Caesar cipher algorithm implementing positive shift or
        # forward shift or right shift
        for i in plaintext:
          __snake_case				:			str            =    self.__key_list.index(UpperCAmelCase				)
          encoded_message += self.__key_list[
              (position + self.__shift_key) % len(self.__key_list				)
          ]

        return encoded_message







def  lowerCAmelCase__(		lowercase    :      str = "Hello, this is a modified Caesar cipher"			)	->      str:
  __snake_case				:			Tuple            =    ShuffledShiftCipher()
  return cipa.decrypt(cipa.encrypt(lowercase			)			)


if __name__ == "__main__":
     import doctest

     doctest.testmod()








import numpy as np
from cva import destroyAllWindows, imread, imshow, waitKey




class 			_lowerCamelCase	:



      """simple docstring"""






      def __init__(	self			,  UpperCAmelCase			,  UpperCAmelCase				)    ->				str:






        '''simple docstring'''






        __snake_case				:			int            =    0
        # max greyscale value for #FFFFFF
        __snake_case				:			int            =    int(self.get_greyscale(255			,  255			,  255				)				)

        if not self.min_threshold < threshold < self.max_threshold:
          __snake_case				:			Tuple            =    F"""Factor value should be from 0 to {self.max_threshold}"""
          raise ValueError(UpperCAmelCase				)

        __snake_case				:			List[Any]            =    input_img
        __snake_case				:			Any            =    threshold
        __snake_case      ,				__snake_case				:			str            =    self.input_img.shape[1], self.input_img.shape[0]

        # error table size (+4 columns and +1 row) greater than input image because of
        # lack of if statements
        __snake_case				:			Dict            =    [
            [0 for _ in range(self.height + 4				)] for __ in range(self.width + 1				)
        ]
        __snake_case				:			str            =    np.ones((self.width, self.height, 3)			,  np.uinta				) * 255







      @classmethod
      def   UpperCAmelCase						(	cls			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase				)    ->				float:






        '''simple docstring'''






        return 0.114 * blue + 0.587 * green + 0.2_126 * red







      def   UpperCAmelCase						(	self				)    ->				None:






        '''simple docstring'''






        for y in range(self.height				):
          for x in range(self.width				):
            __snake_case				:			Optional[int]            =    int(self.get_greyscale(*self.input_img[y][x]				)				)
            if self.threshold > greyscale + self.error_table[y][x]:
              __snake_case				:			Any            =    (0, 0, 0)
              __snake_case				:			Optional[int]            =    greyscale + self.error_table[x][y]
            else:
              __snake_case				:			str            =    (255, 255, 255)
              __snake_case				:			Dict            =    greyscale + self.error_table[x][y] - 255
            self.error_table[y][x + 1] += int(8 / 32 * current_error				)
            self.error_table[y][x + 2] += int(4 / 32 * current_error				)
            self.error_table[y + 1][x] += int(8 / 32 * current_error				)
            self.error_table[y + 1][x + 1] += int(4 / 32 * current_error				)
            self.error_table[y + 1][x + 2] += int(2 / 32 * current_error				)
            self.error_table[y + 1][x - 1] += int(4 / 32 * current_error				)
            self.error_table[y + 1][x - 2] += int(2 / 32 * current_error				)


if __name__ == "__main__":
     # create Burke's instances with original images in greyscale
     _UpperCamelCase    =	[
         Burkes(imread('''image_data/lena.jpg''', 1), threshold)
         for threshold in (1, 126, 130, 140)
     ]

     for burkes in burkes_instances:
          burkes.process()

     for burkes in burkes_instances:
          imshow(
              F'''Original image with dithering threshold: {burkes.threshold}''',
              burkes.output_img,
          )

     waitKey(0)
     destroyAllWindows()

