

"""simple docstring"""






import os
import sys
import time

from . import transposition_cipher as trans_cipher
def       UpperCamelCase					(			)				->			None:
	_UpperCAmelCase    :							List[Any]									=					"""Prehistoric Men.txt"""
	_UpperCAmelCase    :							List[str]									=					"""Output.txt"""
	_UpperCAmelCase    :							Tuple									=					int(input("""Enter key: """ ) )
	_UpperCAmelCase    :							int									=					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]''' )
		_UpperCAmelCase    :							str									=					input("""> """ )
		if not response.lower().startswith("""y""" ):
			sys.exit()

	_UpperCAmelCase    :							Tuple									=					time.time()
	if mode.lower().startswith("""e""" ):
		with open(_lowerCAmelCase ) as f:
			_UpperCAmelCase    :							Union[str, Any]									=					f.read()
		_UpperCAmelCase    :							Optional[Any]									=					trans_cipher.encrypt_message(_lowerCAmelCase,  _lowerCAmelCase )
	elif mode.lower().startswith("""d""" ):
		with open(_lowerCAmelCase ) as f:
			_UpperCAmelCase    :							Union[str, Any]									=					f.read()
		_UpperCAmelCase    :							str									=					trans_cipher.decrypt_message(_lowerCAmelCase,  _lowerCAmelCase )

	with open(_lowerCAmelCase,  """w""" ) as output_obj:
		output_obj.write(_lowerCAmelCase )

	_UpperCAmelCase    :							Dict									=					round(time.time() - start_time,  2 )
	print(("""Done (""", total_time, """seconds )""") )


if __name__ == "__main__":
						main()








"""simple docstring"""






def       UpperCamelCase					(			_lowerCAmelCase     :						int,  _lowerCAmelCase     :						int = 1000 )				->			str:
	if (not isinstance(_lowerCAmelCase,  _lowerCAmelCase )) or (digit_position <= 0):
		raise ValueError("""Digit position must be a positive integer""" )
	elif (not isinstance(_lowerCAmelCase,  _lowerCAmelCase )) or (precision < 0):
		raise ValueError("""Precision must be a nonnegative integer""" )

	# compute an approximation of (16 ** (n - 1)) * pi whose fractional part is mostly
	# accurate
	_UpperCAmelCase    :							List[Any]									=					(
	    4 * _subsum(_lowerCAmelCase,  1,  _lowerCAmelCase )
	    - 2 * _subsum(_lowerCAmelCase,  4,  _lowerCAmelCase )
	    - _subsum(_lowerCAmelCase,  5,  _lowerCAmelCase )
	    - _subsum(_lowerCAmelCase,  6,  _lowerCAmelCase )
	)

	# return the first hex digit of the fractional part of the result
	return hex(int((sum_result % 1) * 16 ) )[2:]
def       UpperCamelCase					(			_lowerCAmelCase     :						int,  _lowerCAmelCase     :						int,  _lowerCAmelCase     :						int )				->			float:
	_UpperCAmelCase    :							Optional[int]									=					0.0
	for sum_index in range(digit_pos_to_extract + precision ):
		_UpperCAmelCase    :							Optional[Any]									=					8 * sum_index + denominator_addend
		if sum_index < digit_pos_to_extract:
			# if the exponential term is an integer and we mod it by the denominator
			# before dividing, only the integer part of the sum will change;
			# the fractional part will not
			_UpperCAmelCase    :							Optional[Any]									=					pow(
			    16,  digit_pos_to_extract - 1 - sum_index,  _lowerCAmelCase )
		else:
			_UpperCAmelCase    :							int									=					pow(16,  digit_pos_to_extract - 1 - sum_index )
		total += exponential_term / denominator
	return total


if __name__ == "__main__":
						import doctest

						doctest.testmod()





