mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-18 09:10:16 +00:00
07e991d553
* ci(pre-commit): Add pep8-naming to `pre-commit` hooks (#7038) * refactor: Fix naming conventions (#7038) * Update arithmetic_analysis/lu_decomposition.py Co-authored-by: Christian Clauss <cclauss@me.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor(lu_decomposition): Replace `NDArray` with `ArrayLike` (#7038) * chore: Fix naming conventions in doctests (#7038) * fix: Temporarily disable project euler problem 104 (#7069) * chore: Fix naming conventions in doctests (#7038) Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import os
|
|
import sys
|
|
import time
|
|
|
|
from . import transposition_cipher as trans_cipher
|
|
|
|
|
|
def main() -> None:
|
|
input_file = "Prehistoric Men.txt"
|
|
output_file = "Output.txt"
|
|
key = int(input("Enter key: "))
|
|
mode = input("Encrypt/Decrypt [e/d]: ")
|
|
|
|
if not os.path.exists(input_file):
|
|
print(f"File {input_file} does not exist. Quitting...")
|
|
sys.exit()
|
|
if os.path.exists(output_file):
|
|
print(f"Overwrite {output_file}? [y/n]")
|
|
response = input("> ")
|
|
if not response.lower().startswith("y"):
|
|
sys.exit()
|
|
|
|
start_time = time.time()
|
|
if mode.lower().startswith("e"):
|
|
with open(input_file) as f:
|
|
content = f.read()
|
|
translated = trans_cipher.encrypt_message(key, content)
|
|
elif mode.lower().startswith("d"):
|
|
with open(output_file) as f:
|
|
content = f.read()
|
|
translated = trans_cipher.decrypt_message(key, content)
|
|
|
|
with open(output_file, "w") as output_obj:
|
|
output_obj.write(translated)
|
|
|
|
total_time = round(time.time() - start_time, 2)
|
|
print(("Done (", total_time, "seconds )"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|