Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#!/usr/bin/env python3# ########################################################################### ## shebang: 1 ## ::: :::::::: ## ft_vault_security.py :+: :+: :+: ## +:+ +:+ +:+ ## By: jkrishna <jkrishna@student.42.fr> +#+ +:+ +#+ ## +#+#+#+#+#+ +#+ ## Created: 2026/07/02 11:32:17 by jkrishna #+# #+# ## Updated: 2026/07/02 12:32:44 by jkrishna ### ########.fr ## ## ########################################################################### #
def secure_archive( file_name: str, action: str = "r", content: str = "") -> tuple[bool, str]: try: with open(file_name, action) as file: if action == 'r': data = file.read() return (True, data) elif action == 'w': file.write(content) return (True, 'Content successfully written to file') return (False, 'Unknown action') except Exception as e: return (False, str(e))
if __name__ == "__main__": print("=== Cyber Archives Security ===")
print("\nUsing 'secure_archive' to read from a nonexistent file:") print(secure_archive('/not/existing/file', 'r'))
print("\nUsing 'secure_archive' to read from an inaccessible file:") print(secure_archive('/etc/shadow', 'r'))
print("\nUsing 'secure_archive' to read from a regular file:") result = secure_archive('ancient_fragment.txt') print(result)
print("\nUsing 'secure_archive' to write previous content to a new file:") print(secure_archive('jay.txt', 'w', result[1]))