

import os
import sys
import time

from . import transposition_cipher as trans_cipher





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

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

  __UpperCAmelCase	:  Tuple		=     time.time()
  if mode.lower().startswith('e'  ):
    with open(snake_case_  ) as f:
      __UpperCAmelCase	:  Optional[Any]		=     f.read()
    __UpperCAmelCase	:  int		=     trans_cipher.encrypt_message(snake_case_    ,       snake_case_  )
  elif mode.lower().startswith('d'  ):
    with open(snake_case_  ) as f:
      __UpperCAmelCase	:  int		=     f.read()
    __UpperCAmelCase	:  List[str]		=     trans_cipher.decrypt_message(snake_case_    ,       snake_case_  )

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

  __UpperCAmelCase	:  List[str]		=     round(time.time() - start_time    ,       2  )
  print(('Done (', total_time, 'seconds )')  )


if __name__ == "__main__":
      main()








from __future__ import annotations





def  _snake_case		(snake_case_					:     str  )							->		bool:
  __UpperCAmelCase	:  int
  __UpperCAmelCase	:  list[str]		=     list(snake_case_  )
  __UpperCAmelCase,			__UpperCAmelCase	:  Any		=     _vector[:-1], int(_vector[-1]  )
  __UpperCAmelCase	:  list[int]		=     [int(snake_case_  ) for digit in __vector]

  vector.reverse()
  for i, digit in enumerate(snake_case_  ):
    if i & 1 == 0:
      __UpperCAmelCase	:  int		=     digit * 2
      if doubled > 9:
        doubled -= 9
      check_digit += doubled
    else:
      check_digit += digit

  return check_digit % 10 == 0


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      assert is_luhn('''79927398713''')
      assert not is_luhn('''79927398714''')





