Skip to content

fix: remove commets, fix bugs #1

Description

@0xbitx

import os
import argparse

banner = """
┬─┐┌─┐┬ ┬┌─┐┬─┐┌─┐┌─┐ ┌─┐┬┌─┐┬ ┬┌─┐┬─┐
├┬┘├┤ └┐┌┘├┤ ├┬┘└─┐├┤ │ │├─┘├─┤├┤ ├┬┘
┴└─└─┘ └┘ └─┘┴└─└─┘└─┘ └─┘┴┴ ┴ ┴└─┘┴└─
"""

def reverse_cipher(plaintext):
ciphertext = ""
for char in plaintext:
if char.isalpha():
if char.isupper():
cipher_char = chr(155 - ord(char))
else:
cipher_char = chr(219 - ord(char))
else:
cipher_char = char
ciphertext += cipher_char
return ciphertext

def encrypt_text(plaintext):
return reverse_cipher(plaintext)

def decrypt_text(ciphertext):
return reverse_cipher(ciphertext)

os.system("clear")
print(banner)

parser = argparse.ArgumentParser(description='Reverse Cipher - A simple tool that allows you to encrypt or decrypt text using a basic substitution cipher.')
parser.add_argument('-e', '--enc', action='store_true', help='Encrypt the text')
parser.add_argument('-d', '--dec', action='store_true', help='Decrypt the text')
parser.add_argument('-t', '--text', type=str, help='Text to be processed')
parser.add_argument('-f', '--file', type=str, help='Path to the input file')
parser.add_argument('-o', '--output', type=str, help='Path to the output file')

args = parser.parse_args()

if args.enc and args.dec:
print("Error: Please specify either encryption (-e/--enc) or decryption (-d/--dec), not both.")
elif not args.enc and not args.dec:
print("Error: Please specify either encryption (-e/--enc) or decryption (-d/--dec).")
elif args.text is None and args.file is None:
parser.print_help()
print("Error: Please provide the text to be processed (-t/--text) or specify a file (-f/--file).")
else:
if args.text:
if args.enc:
result = encrypt_text(args.text)
print("Encrypted Text:", result)
elif args.dec:
result = decrypt_text(args.text)
print("Decrypted Text:", result)
elif args.file:
try:
with open(args.file, 'r') as file:
text = file.read().strip()
if args.enc:
result = encrypt_text(text)
if args.output:
with open(args.output, 'w') as output_file:
output_file.write(result)
print("Encryption result written to", args.output)
else:
print("Encrypted Text:", result)
elif args.dec:
result = decrypt_text(text)
if args.output:
with open(args.output, 'w') as output_file:
output_file.write(result)
print("Decryption result written to", args.output)
else:
print("Decrypted Text:", result)
except FileNotFoundError:
print("Error: The specified file does not exist.")

if not any(vars(args).values()):
parser.print_help()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions