-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathScrambleNinja.py
114 lines (90 loc) · 5.12 KB
/
ScrambleNinja.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os; import time; import re
from termcolor import colored
import colorama
byteList = []
colorama.init()
BANNER1 = colored('''
██████ ▄████▄ ██▀███ ▄▄▄ ███▄ ▄███▓ ▄▄▄▄ ██▓ ▓█████ ███▄ █ ██▓ ███▄ █ ▄▄▄██▀▀▀▄▄▄
▒██ ▒ ▒██▀ ▀█ ▓██ ▒ ██▒▒████▄ ▓██▒▀█▀ ██▒▓█████▄ ▓██▒ ▓█ ▀ ██ ▀█ █ ▓██▒ ██ ▀█ █ ▒██ ▒████▄
░ ▓██▄ ▒▓█ ▄ ▓██ ░▄█ ▒▒██ ▀█▄ ▓██ ▓██░▒██▒ ▄██▒██░ ▒███ ▓██ ▀█ ██▒▒██▒▓██ ▀█ ██▒ ░██ ▒██ ▀█▄
▒ ██▒▒▓▓▄ ▄██▒▒██▀▀█▄ ░██▄▄▄▄██ ▒██ ▒██ ▒██░█▀ ▒██░ ▒▓█ ▄ ▓██▒ ▐▌██▒░██░▓██▒ ▐▌██▒▓██▄██▓ ░██▄▄▄▄██
▒██████▒▒▒ ▓███▀ ░░██▓ ▒██▒ ▓█ ▓██▒▒██▒ ░██▒░▓█ ▀█▓░██████▒░▒████▒▒██░ ▓██░░██░▒██░ ▓██░ ▓███▒ ▓█ ▓██▒
▒ ▒▓▒ ▒ ░░ ░▒ ▒ ░░ ▒▓ ░▒▓░ ▒▒ ▓▒█░░ ▒░ ░ ░░▒▓███▀▒░ ▒░▓ ░░░ ▒░ ░░ ▒░ ▒ ▒ ░▓ ░ ▒░ ▒ ▒ ▒▓▒▒░ ▒▒ ▓▒█░
░ ░▒ ░ ░ ░ ▒ ░▒ ░ ▒░ ▒ ▒▒ ░░ ░ ░▒░▒ ░ ░ ░ ▒ ░ ░ ░ ░░ ░░ ░ ▒░ ▒ ░░ ░░ ░ ▒░ ▒ ░▒░ ▒ ▒▒ ░
░ ░ ░ ░ ░░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ▒
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░''', 'blue')
BANNER2 = colored(''' -----------------------------------------------------''', 'blue')
BANNER3 = colored(''' || ScrambleNinja: The File Scrambler & Unscrambler ||''', 'red')
BANNER4 = colored(''' -----------------------------------------------------''', 'blue')
def printBanner():
print(BANNER1), print(BANNER2), print(BANNER3), print(BANNER4)
def operate():
with open(filePath, "rb") as inputFile:
for line in inputFile:
byteList.append(line)
if (operation == "1"):
byteList.insert(-1, b'\r\n')
length = len(byteList)
half = length // 2
with open(output, "wb") as outputFile:
for element in byteList[half::-1]:
outputFile.write(element)
for element in byteList[:half:-1]:
outputFile.write(element)
def clrscr():
if os.name == 'posix':
_ = os.system('clear')
else:
_ = os.system('cls')
printBanner()
def outputFileName():
try:
outputMatch = re.search(r"(.+)[$\.].+", filePath)
output = str(outputMatch[1])
extensionMatch = re.search(r".+[$\.](.+)", filePath)
extension = str(extensionMatch[1])
except:
output = filePath
extension = ""
if (operation == "1"):
output += " [Scrambled]." + extension
elif (operation == "2"):
output += " [Unscrambled]." + extension
return(output)
############### Main ###############
if __name__ == "__main__":
printBanner()
try:
while (True):
print("Operations:-")
print("1. Scramble a file\n2. Unscramble a file")
operation = input("\nSelect operation number: ")
if (operation in ["1", "2"]):
while (True):
filePath = input("\nEnter file path: ")
if (os.path.isfile(filePath) is True):
break
else:
clrscr()
print("\nEither file does not exist or invalid path entered. Try again.")
continue
clrscr()
output = outputFileName()
print("\nWorking...", end='')
start = time.time()
operate()
break
else:
clrscr()
print("\nInvalid entry. Choose either option 1 or 2. Try again.\n")
continue
completionTime = time.time() - start
clrscr()
print(f"\nThe task completed successfully in {completionTime} seconds.")
print("Press Enter to exit. GG;WP.")
input()
except KeyboardInterrupt:
clrscr()
print("\nCTRL ^C\n\nThrew a wrench in the works.")
print("Press Enter to exit.")
input()