






from __future__ import annotations

from typing import Any



class 							_UpperCamelCase			:

      '''simple docstring'''





      def __init__(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase = 0	)->	Union[str, Any]:
           __lowerCAmelCase			, __lowerCAmelCase								=					row, column
           __lowerCAmelCase								=					[[default_value for c in range(SCREAMING_SNAKE_CASE_	)] for r in range(SCREAMING_SNAKE_CASE_	)]


      def __str__(	self	)->	Any:
           __lowerCAmelCase								=					F"""Matrix consist of {self.row} rows and {self.column} columns\n"""

           # Make string identifier
           __lowerCAmelCase								=					0
           for row_vector in self.array:
                for obj in row_vector:
                     __lowerCAmelCase								=					max(SCREAMING_SNAKE_CASE_					,						len(str(SCREAMING_SNAKE_CASE_	)	)	)
           __lowerCAmelCase								=					F"""%{max_element_length}s"""

           # Make string and return
           def single_line(__UpperCamelCase	) -> str:
                nonlocal string_format_identifier
                __lowerCAmelCase								=					"["
                line += ", ".join(string_format_identifier % (obj,) for obj in row_vector	)
                line += "]"
                return line

           s += "\n".join(single_line(SCREAMING_SNAKE_CASE_	) for row_vector in self.array	)
           return s


      def __repr__(	self	)->	List[Any]:
           return str(self	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase	)->	List[Any]:
           if not (isinstance(SCREAMING_SNAKE_CASE_					,						(list, tuple)	) and len(SCREAMING_SNAKE_CASE_	) == 2):
                return False
           elif not (0 <= loc[0] < self.row and 0 <= loc[1] < self.column):
                return False
           else:
                return True


      def __getitem__(	self					,						__UpperCamelCase	)->	Tuple:
           assert self.validate_indicies(SCREAMING_SNAKE_CASE_	)
           return self.array[loc[0]][loc[1]]


      def __setitem__(	self					,						__UpperCamelCase					,						__UpperCamelCase	)->	int:
           assert self.validate_indicies(SCREAMING_SNAKE_CASE_	)
           __lowerCAmelCase								=					value


      def __add__(	self					,						__UpperCamelCase	)->	List[str]:
           assert isinstance(SCREAMING_SNAKE_CASE_					,						SCREAMING_SNAKE_CASE_	)
           assert self.row == another.row and self.column == another.column

           # Add
           __lowerCAmelCase								=					Matrix(self.row					,						self.column	)
           for r in range(self.row	):
                for c in range(self.column	):
                     __lowerCAmelCase								=					self[r, c] + another[r, c]
           return result


      def __neg__(	self	)->	Optional[Any]:
           __lowerCAmelCase								=					Matrix(self.row					,						self.column	)
           for r in range(self.row	):
                for c in range(self.column	):
                     __lowerCAmelCase								=					-self[r, c]
           return result


      def __sub__(	self					,						__UpperCamelCase	)->	Union[str, Any]:
           return self + (-another)


      def __mul__(	self					,						__UpperCamelCase	)->	List[Any]:

           if isinstance(SCREAMING_SNAKE_CASE_					,						(int, float)	):  # Scalar multiplication
                __lowerCAmelCase								=					Matrix(self.row					,						self.column	)
                for r in range(self.row	):
                     for c in range(self.column	):
                          __lowerCAmelCase								=					self[r, c] * another
                return result
           elif isinstance(SCREAMING_SNAKE_CASE_					,						SCREAMING_SNAKE_CASE_	):  # Matrix multiplication
                assert self.column == another.row
                __lowerCAmelCase								=					Matrix(self.row					,						another.column	)
                for r in range(self.row	):
                     for c in range(another.column	):
                          for i in range(self.column	):
                               result[r, c] += self[r, i] * another[i, c]
                return result
           else:
                __lowerCAmelCase								=					F"""Unsupported type given for another ({type(SCREAMING_SNAKE_CASE_	)})"""
                raise TypeError(SCREAMING_SNAKE_CASE_	)


      def  __UpperCAmelCase		(	self	)->	str:
           __lowerCAmelCase								=					Matrix(self.column					,						self.row	)
           for r in range(self.row	):
                for c in range(self.column	):
                     __lowerCAmelCase								=					self[r, c]
           return result


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase	)->	List[str]:
           assert isinstance(SCREAMING_SNAKE_CASE_					,						SCREAMING_SNAKE_CASE_	) and isinstance(SCREAMING_SNAKE_CASE_					,						SCREAMING_SNAKE_CASE_	)
           assert self.row == self.column == u.row == v.row  # u, v should be column vector
           assert u.column == v.column == 1  # u, v should be column vector

           # Calculate
           __lowerCAmelCase								=					v.transpose()
           __lowerCAmelCase								=					(v_t * self * u)[0, 0] + 1
           if numerator_factor == 0:
                return None  # It's not invertable
           return self - ((self * u) * (v_t * self) * (1.0 / numerator_factor))


# Testing
if __name__ == "__main__":





 def       __lowerCAmelCase      (						):
      __lowerCAmelCase								=					Matrix(3					, 3					, 0       )
      for i in range(3       ):
           __lowerCAmelCase								=					1
      print(F"""a^(-1) is {ainv}"""       )
      # u, v
      __lowerCAmelCase								=					Matrix(3					, 1					, 0       )
      __lowerCAmelCase			, __lowerCAmelCase			, __lowerCAmelCase								=					1, 2, -3
      __lowerCAmelCase								=					Matrix(3					, 1					, 0       )
      __lowerCAmelCase			, __lowerCAmelCase			, __lowerCAmelCase								=					4, -2, 5
      print(F"""u is {u}"""       )
      print(F"""v is {v}"""       )
      print(F"""uv^T is {u * v.transpose()}"""       )
      # Sherman Morrison
      print(F"""(a + uv^T)^(-1) is {ainv.sherman_morrison(__a					, __a       )}"""       )





 def       __lowerCAmelCase      (						):
      import doctest

      doctest.testmod()



 testa()














import random



class 							_UpperCamelCase			:


      @staticmethod
      def  __UpperCAmelCase		(	__UpperCamelCase	)->	tuple[list[int], list[int]]:
           __lowerCAmelCase								=					[ord(__UpperCamelCase	) for i in text]
           __lowerCAmelCase								=					[]
           __lowerCAmelCase								=					[]
           for i in plain:
                __lowerCAmelCase								=					random.randint(1					,						3_0_0	)
                __lowerCAmelCase								=					(i + k) * k
                cipher.append(__UpperCamelCase	)
                key.append(__UpperCamelCase	)
           return cipher, key


      @staticmethod
      def  __UpperCAmelCase		(	__UpperCamelCase					,						__UpperCamelCase	)->	str:
           __lowerCAmelCase								=					[]
           for i in range(len(__UpperCamelCase	)	):
                __lowerCAmelCase								=					int((cipher[i] - (key[i]) ** 2) / key[i]	)
                plain.append(chr(__UpperCamelCase	)	)
           return "".join(__UpperCamelCase	)


if __name__ == "__main__":
 lowerCamelCase      ,					lowerCamelCase			:					List[Any]         =	Onepad().encrypt('''Hello''')
 print(c, k)
 print(Onepad().decrypt(c, k))






