






import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast



@dataclass
class   lowerCamelCase				(datasets.BuilderConfig      ):







		'''simple docstring'''



		_snake_case   :   Optional[datasets.Features]							=  None





class   lowerCamelCase				(datasets.ArrowBasedBuilder      ):







		'''simple docstring'''



		_snake_case   :   Union[str, Any]							=  PandasConfig



		def  __UpperCAmelCase      (							self       )     ->							Tuple:
							return datasets.DatasetInfo(features=self.config.features       )



		def  __UpperCAmelCase      (							self    ,		_UpperCamelCase       )     ->							Optional[Any]:
							if not self.config.data_files:
												raise ValueError(f"At least one data file must be specified, but got data_files={self.config.data_files}"       )
							UpperCAmelCase_   :				List[str]						=						dl_manager.download_and_extract(self.config.data_files       )
							if isinstance(_UpperCamelCase    ,		(str, list, tuple)       ):
												UpperCAmelCase_   :				Union[str, Any]						=						data_files
												if isinstance(_UpperCamelCase    ,		_UpperCamelCase       ):
																	UpperCAmelCase_   :				Optional[int]						=						[files]
												# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
												UpperCAmelCase_   :				List[str]						=						[dl_manager.iter_files(_UpperCamelCase       ) for file in files]
												return [datasets.SplitGenerator(name=datasets.Split.TRAIN    ,		gen_kwargs={'files': files}       )]
							UpperCAmelCase_   :				str						=						[]
							for split_name, files in data_files.items():
												if isinstance(_UpperCamelCase    ,		_UpperCamelCase       ):
																	UpperCAmelCase_   :				Union[str, Any]						=						[files]
												# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
												UpperCAmelCase_   :				List[str]						=						[dl_manager.iter_files(_UpperCamelCase       ) for file in files]
												splits.append(datasets.SplitGenerator(name=_UpperCamelCase    ,		gen_kwargs={'files': files}       )       )
							return splits



		def  __UpperCAmelCase      (							self    ,		_UpperCamelCase       )     ->							pa.Table:
							if self.config.features is not None:
												# more expensive cast to support nested features with keys in a different order
												# allows str <-> int/float or str to Audio for example
												UpperCAmelCase_   :				Optional[Any]						=						table_cast(_UpperCamelCase    ,		self.config.features.arrow_schema       )
							return pa_table



		def  __UpperCAmelCase      (							self    ,		_UpperCamelCase       )     ->							Dict:
							for i, file in enumerate(itertools.chain.from_iterable(_UpperCamelCase       )       ):
												with open(_UpperCamelCase    ,		'rb'       ) as f:
																	UpperCAmelCase_   :				List[str]						=						pa.Table.from_pandas(pd.read_pickle(_UpperCamelCase       )       )
																	yield i, self._cast_table(_UpperCamelCase       )














def 					lowercase__				(					__snake_case   :							Tuple					,	__snake_case   :							List[Any]  ):


					'''simple docstring'''


					UpperCAmelCase_   :				Any						=						''
					for i in table:
										res += inp[i - 1]
					return res




def 					lowercase__				(					__snake_case   :							Optional[int]  ):


					'''simple docstring'''


					return data[1:] + data[0]




def 					lowercase__				(					__snake_case   :							Union[str, Any]					,	__snake_case   :							Optional[int]  ):


					'''simple docstring'''


					UpperCAmelCase_   :				Any						=						''
					for i in range(len(__snake_case  )  ):
										if a[i] == b[i]:
															res += "0"
										else:
															res += "1"
					return res




def 					lowercase__				(					__snake_case   :							Dict					,	__snake_case   :							Optional[int]  ):


					'''simple docstring'''


					UpperCAmelCase_   :				Optional[Any]						=						int('0b' + data[0] + data[-1]					,	2  )
					UpperCAmelCase_   :				Any						=						int('0b' + data[1:3]					,	2  )
					return bin(s[row][col]  )[2:]




def 					lowercase__				(					__snake_case   :							Tuple					,	__snake_case   :							List[Any]					,	__snake_case   :							List[Any]					,	__snake_case   :							Optional[int]					,	__snake_case   :							str  ):


					'''simple docstring'''


					UpperCAmelCase_   :				Union[str, Any]						=						message[:4]
					UpperCAmelCase_   :				Optional[int]						=						message[4:]
					UpperCAmelCase_   :				Union[str, Any]						=						apply_table(__snake_case					,	__snake_case  )
					UpperCAmelCase_   :				Union[str, Any]						=						xor(__snake_case					,	__snake_case  )
					UpperCAmelCase_   :				Dict						=						apply_sbox(__snake_case					,	temp[:4]  )  # noqa: E741
					UpperCAmelCase_   :				Any						=						apply_sbox(__snake_case					,	temp[4:]  )
					UpperCAmelCase_   :				str						=						'0' * (2 - len(__snake_case  )) + l  # noqa: E741
					UpperCAmelCase_   :				int						=						'0' * (2 - len(__snake_case  )) + r
					UpperCAmelCase_   :				int						=						apply_table(l + r					,	__snake_case  )
					UpperCAmelCase_   :				int						=						xor(__snake_case					,	__snake_case  )
					return temp + right


if __name__ == "__main__":
		__UpperCAmelCase     							=						input('Enter 10 bit key: ')
		__UpperCAmelCase     							=						input('Enter 8 bit message: ')

		__UpperCAmelCase     							=						[6, 3, 7, 4, 8, 5, 10, 9]
		__UpperCAmelCase     							=						[3, 5, 2, 7, 4, 10, 1, 9, 8, 6]
		__UpperCAmelCase     							=						[2, 4, 3, 1]
		__UpperCAmelCase     							=						[2, 6, 3, 1, 4, 8, 5, 7]
		__UpperCAmelCase     							=						[4, 1, 3, 5, 7, 2, 8, 6]
		__UpperCAmelCase     							=						[4, 1, 2, 3, 2, 3, 4, 1]
		__UpperCAmelCase     							=						[[1, 0, 3, 2], [3, 2, 1, 0], [0, 2, 1, 3], [3, 1, 3, 2]]
		__UpperCAmelCase     							=						[[0, 1, 2, 3], [2, 0, 1, 3], [3, 0, 1, 0], [2, 1, 0, 3]]

		# key generation
		__UpperCAmelCase     							=						apply_table(key, paa_table)
		__UpperCAmelCase     							=						temp[:5]
		__UpperCAmelCase     							=						temp[5:]
		__UpperCAmelCase     							=						left_shift(left)
		__UpperCAmelCase     							=						left_shift(right)
		__UpperCAmelCase     							=						apply_table(left + right, pa_table)
		__UpperCAmelCase     							=						left_shift(left)
		__UpperCAmelCase     							=						left_shift(right)
		__UpperCAmelCase     							=						left_shift(left)
		__UpperCAmelCase     							=						left_shift(right)
		__UpperCAmelCase     							=						apply_table(left + right, pa_table)

		# encryption
		__UpperCAmelCase     							=						apply_table(message, IP)
		__UpperCAmelCase     							=						function(expansion, sa, sa, keya, temp)
		__UpperCAmelCase     							=						temp[4:] + temp[:4]
		__UpperCAmelCase     							=						function(expansion, sa, sa, keya, temp)
		__UpperCAmelCase     							=						apply_table(temp, IP_inv)
		print('Cipher text is:', CT)

		# decryption
		__UpperCAmelCase     							=						apply_table(CT, IP)
		__UpperCAmelCase     							=						function(expansion, sa, sa, keya, temp)
		__UpperCAmelCase     							=						temp[4:] + temp[:4]
		__UpperCAmelCase     							=						function(expansion, sa, sa, keya, temp)
		__UpperCAmelCase     							=						apply_table(temp, IP_inv)
		print('Plain text after decypting is:', PT)






