
'''simple docstring'''







from __future__ import annotations

import numpy as np
from numpy import floataa
from numpy.typing import NDArray
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			NDArray[floataa]				,				__SCREAMING_SNAKE_CASE :			NDArray[floataa]				,				__SCREAMING_SNAKE_CASE :			list[int]				,				__SCREAMING_SNAKE_CASE :			int				,				):



						"""simple docstring"""





						lowercase_						,			lowercase_     :					Union[str, Any]													=	coefficient_matrix.shape
						lowercase_						,			lowercase_     :					Any													=	constant_matrix.shape

						if rowsa != colsa:
												lowercase_     :					Dict													=	F'''Coefficient matrix dimensions must be nxn but received {rowsa}x{colsa}'''
												raise ValueError(__SCREAMING_SNAKE_CASE							)

						if colsa != 1:
												lowercase_     :					List[str]													=	F'''Constant matrix must be nx1 but received {rowsa}x{colsa}'''
												raise ValueError(__SCREAMING_SNAKE_CASE							)

						if rowsa != rowsa:
												lowercase_     :					int													=	(
												    '''Coefficient and constant matrices dimensions must be nxn and nx1 but '''
												    F'''received {rowsa}x{colsa} and {rowsa}x{colsa}'''
												)
												raise ValueError(__SCREAMING_SNAKE_CASE							)

						if len(__SCREAMING_SNAKE_CASE							) != rowsa:
												lowercase_     :					List[Any]													=	(
												    '''Number of initial values must be equal to number of rows in coefficient '''
												    F'''matrix but received {len(__SCREAMING_SNAKE_CASE							)} and {rowsa}'''
												)
												raise ValueError(__SCREAMING_SNAKE_CASE							)

						if iterations <= 0:
												raise ValueError('''Iterations must be at least 1'''							)

						lowercase_     :					NDArray[floataa]													=	np.concatenate(
						    (coefficient_matrix, constant_matrix)				,				axis=1							)

						lowercase_						,			lowercase_     :					Optional[Any]													=	table.shape

						strictly_diagonally_dominant(__SCREAMING_SNAKE_CASE							)

						# Iterates the whole matrix for given number of times
						for _ in range(__SCREAMING_SNAKE_CASE							):
												lowercase_     :					List[str]													=	[]
												for row in range(__SCREAMING_SNAKE_CASE							):
																		lowercase_     :					Optional[Any]													=	0
																		for col in range(__SCREAMING_SNAKE_CASE							):
																								if col == row:
																														lowercase_     :					Optional[int]													=	table[row][col]
																								elif col == cols - 1:
																														lowercase_     :					Optional[int]													=	table[row][col]
																								else:
																														temp += (-1) * table[row][col] * init_val[col]
																		lowercase_     :					Optional[int]													=	(temp + val) / denom
																		new_val.append(__SCREAMING_SNAKE_CASE							)
												lowercase_     :					Optional[Any]													=	new_val

						return [float(__SCREAMING_SNAKE_CASE							) for i in new_val]
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			NDArray[floataa]							):



						"""simple docstring"""





						lowercase_						,			lowercase_     :					List[str]													=	table.shape

						lowercase_     :					int													=	True

						for i in range(0				,				__SCREAMING_SNAKE_CASE							):
												lowercase_     :					Optional[int]													=	0
												for j in range(0				,				cols - 1							):
																		if i == j:
																								continue
																		else:
																								total += table[i][j]

												if table[i][i] <= total:
																		raise ValueError('''Coefficient matrix is not strictly diagonally dominant'''							)

						return is_diagonally_dominant


# Test Cases
if __name__ == "__main__":
							import doctest

							doctest.testmod()





'''simple docstring'''







from __future__ import annotations






class 			lowerCAmelCase__       :






					def __init__(       self    ,							__SCREAMING_SNAKE_CASE = 0		):


											"""simple docstring"""





											lowercase_     :					Any													=	key






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											assert isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		) and isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

											lowercase_     :					List[str]													=	key or self.__key or 1

											# make sure key is an appropriate size
											key %= 2_55

											return [chr(ord(__SCREAMING_SNAKE_CASE		) ^ key		) for ch in content]






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											assert isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		) and isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

											lowercase_     :					Optional[int]													=	key or self.__key or 1

											# make sure key is an appropriate size
											key %= 2_55

											return [chr(ord(__SCREAMING_SNAKE_CASE		) ^ key		) for ch in content]






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE = 0		):


											"""simple docstring"""





											assert isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		) and isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

											lowercase_     :					List[Any]													=	key or self.__key or 1

											# make sure key can be any size
											while key > 2_55:
																	key -= 2_55

											# This will be returned
											lowercase_     :					str													=	''''''

											for ch in content:
																	ans += chr(ord(__SCREAMING_SNAKE_CASE		) ^ key		)

											return ans






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE = 0		):


											"""simple docstring"""





											assert isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		) and isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

											lowercase_     :					Any													=	key or self.__key or 1

											# make sure key can be any size
											while key > 2_55:
																	key -= 2_55

											# This will be returned
											lowercase_     :					Dict													=	''''''

											for ch in content:
																	ans += chr(ord(__SCREAMING_SNAKE_CASE		) ^ key		)

											return ans






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE = 0		):


											"""simple docstring"""





											assert isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		) and isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

											try:
																	with open(__SCREAMING_SNAKE_CASE		) as fin, open('''encrypt.out'''    ,							'''w+'''		) as fout:
																							# actual encrypt-process
																							for line in fin:
																													fout.write(self.encrypt_string(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)		)

											except OSError:
																	return False

											return True






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											assert isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		) and isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)

											try:
																	with open(__SCREAMING_SNAKE_CASE		) as fin, open('''decrypt.out'''    ,							'''w+'''		) as fout:
																							# actual encrypt-process
																							for line in fin:
																													fout.write(self.decrypt_string(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)		)

											except OSError:
																	return False

											return True


# Tests
# crypt = XORCipher()
# key = 67

# # test encrypt
# print(crypt.encrypt("hallo welt",key))
# # test decrypt
# print(crypt.decrypt(crypt.encrypt("hallo welt",key), key))

# # test encrypt_string
# print(crypt.encrypt_string("hallo welt",key))

# # test decrypt_string
# print(crypt.decrypt_string(crypt.encrypt_string("hallo welt",key),key))

# if (crypt.encrypt_file("test.txt",key)):
#       print("encrypt successful")
# else:
#       print("encrypt unsuccessful")

# if (crypt.decrypt_file("encrypt.out",key)):
#       print("decrypt successful")
# else:
#       print("decrypt unsuccessful")



