Created
May 9, 2020 22:08
-
-
Save bascoe10/4e76d772f761a874b089c28ec112120d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import argparse | |
def encrypt(text, key): | |
keylen = len(key) | |
keyPos = 0 | |
encrypted = "" | |
for x in text: | |
keyChr = key[keyPos] | |
newChr = ord(x) | |
newChr = chr((newChr + ord(keyChr)) % 255) | |
encrypted += newChr | |
keyPos += 1 | |
keyPos = keyPos % keylen | |
return encrypted | |
def decrypt(text, key): | |
keylen = len(key) | |
keyPos = 0 | |
decrypted = "" | |
for x in text: | |
keyChr = key[keyPos] | |
newChr = ord(x) | |
newChr = chr((newChr - ord(keyChr)) % 255) | |
decrypted += newChr | |
keyPos += 1 | |
keyPos = keyPos % keylen | |
return decrypted | |
parser = argparse.ArgumentParser(description='Encrypt with 0bscura\'s encryption algorithm') | |
parser.add_argument('-i', | |
metavar='InFile', | |
type=str, | |
help='The file to read', | |
required=False) | |
parser.add_argument('-o', | |
metavar='OutFile', | |
type=str, | |
help='Where to output the encrypted/decrypted file', | |
required=False) | |
parser.add_argument('-k', | |
metavar='Key', | |
type=str, | |
help='Key to use', | |
required=False) | |
parser.add_argument('-d', action='store_true', help='Decrypt mode') | |
args = parser.parse_args() | |
banner = "################################\n" | |
banner+= "# BEGINNING #\n" | |
banner+= "# SUPER SECURE ENCRYPTOR #\n" | |
banner+= "################################\n" | |
banner += " ############################\n" | |
banner += " # FILE MODE #\n" | |
banner += " ############################" | |
print(banner) | |
if args.o == None or args.k == None or args.i == None: | |
print("Missing args") | |
else: | |
if args.d: | |
print("Opening file {0}...".format(args.i)) | |
with open(args.i, 'r', encoding='UTF-8') as f: | |
data = f.read() | |
print("Decrypting...") | |
decrypted = decrypt(data, args.k) | |
print("Writing to {0}...".format(args.o)) | |
with open(args.o, 'w', encoding='UTF-8') as f: | |
f.write(decrypted) | |
else: | |
print("Opening file {0}...".format(args.i)) | |
with open(args.i, 'r', encoding='UTF-8') as f: | |
data = f.read() | |
print("Encrypting...") | |
encrypted = encrypt(data, args.k) | |
print("Writing to {0}...".format(args.o)) | |
with open(args.o, 'w', encoding='UTF-8') as f: | |
f.write(encrypted) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment