




import os
import sys
import time

from . import transposition_cipher as trans_cipher


def 				_a       (				)->  None:
		SCREAMING_SNAKE_CASE_							=       'Prehistoric Men.txt'
		SCREAMING_SNAKE_CASE_							=       'Output.txt'
		SCREAMING_SNAKE_CASE_							=       int(input('Enter key: '   )   )
		SCREAMING_SNAKE_CASE_							=       input('Encrypt/Decrypt [e/d]: '   )

		if not os.path.exists(lowerCAmelCase   ):
				print(F'''File {input_file} does not exist. Quitting...'''   )
				sys.exit()
		if os.path.exists(lowerCAmelCase   ):
				print(F'''Overwrite {output_file}? [y/n]'''   )
				SCREAMING_SNAKE_CASE_							=       input('> '   )
				if not response.lower().startswith('y'   ):
						sys.exit()

		SCREAMING_SNAKE_CASE_							=       time.time()
		if mode.lower().startswith('e'   ):
				with open(lowerCAmelCase   ) as f:
						SCREAMING_SNAKE_CASE_							=       f.read()
				SCREAMING_SNAKE_CASE_							=       trans_cipher.encrypt_message(lowerCAmelCase						,	lowerCAmelCase   )
		elif mode.lower().startswith('d'   ):
				with open(lowerCAmelCase   ) as f:
						SCREAMING_SNAKE_CASE_							=       f.read()
				SCREAMING_SNAKE_CASE_							=       trans_cipher.decrypt_message(lowerCAmelCase						,	lowerCAmelCase   )

		with open(lowerCAmelCase						,	'w'   ) as output_obj:
				output_obj.write(lowerCAmelCase   )

		SCREAMING_SNAKE_CASE_							=       round(time.time() - start_time						,	2   )
		print(('Done (', total_time, 'seconds )')   )


if __name__ == "__main__":
						main()





from __future__ import annotations

import random
import string



class       lowercase_		:



						def __init__( self  :      str				,       snake_case__  :      str | None = None     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       passcode or self.__passcode_creator()
								SCREAMING_SNAKE_CASE_							=       self.__make_key_list()
								SCREAMING_SNAKE_CASE_							=       self.__make_shift_key()



						def __str__( self  :      List[Any]     ):

								"""simple docstring"""

								return "".join(self.__passcode     )



						def   __a				( self  :      Union[str, Any]				,       snake_case__  :      list[int]     ):

								"""simple docstring"""

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



						def   __a				( self  :      str     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       string.ascii_letters + string.digits
								SCREAMING_SNAKE_CASE_							=       [random.choice(snake_case__     ) for _ in range(random.randint(10				,       20     )     )]
								return password



						def   __a				( self  :      str     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       (
								    string.ascii_letters + string.digits + string.punctuation + ' \t\n'
								)

								SCREAMING_SNAKE_CASE_							=       []

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

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

										# 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   __a				( self  :      Union[str, Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       sum(self.__neg_pos([ord(snake_case__     ) for x in self.__passcode]     )     )
								return num if num > 0 else len(self.__passcode     )



						def   __a				( self  :      str				,       snake_case__  :      str     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       ''

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

								return decoded_message






						def   __a				( self  :      Optional[int]				,       snake_case__  :      str     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       ''

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

								return encoded_message


def 				_a       (				lowerCAmelCase = "Hello, this is a modified Caesar cipher"   )->  str:
		SCREAMING_SNAKE_CASE_							=       ShuffledShiftCipher()
		return cipa.decrypt(cipa.encrypt(lowerCAmelCase   )   )


if __name__ == "__main__":
						import doctest

						doctest.testmod()