-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcypher.py
53 lines (42 loc) · 1.63 KB
/
cypher.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
# -*- coding: utf-8 -*-
"""
|========|
| CYPHER |
|========|
Created on Tue Apr 27 23:36:04 2021
@author: Bobby (Github: ovrhuman)
"""
import random
import sys
filepath = sys.argv[1]
password = input("Enter password (cap sensitive)\n>> ")
en_or_decrypt = "select"
while en_or_decrypt.lower() not in ["e","d"]:
en_or_decrypt = input("Encrypt or decrypt? [e/d]\n>> ")
if en_or_decrypt.lower() not in ["e","d"]: print("invalid input..")
with open(filepath) as infile:
test = infile.read()
chars = list('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ 0123456789')
n_chars = len(chars)
seed = sum([chars.index(x) for x in password])
random.seed(seed)
cipher_key = [random.randint(0,200) for i in range(100)]
if en_or_decrypt.lower() == "d":
chars = chars[-1::-1]
new_text = ""
for i in range(len(list(test))):
if test[i] in chars:
key = cipher_key[i % len(cipher_key)]
new_text += (chars[((chars.index(test[i]))+key)%len(chars)])
else:
new_text += (test[i])
extension = ""
outfilepath = filepath[:filepath.rindex(".")]
if outfilepath != filepath:
extension = filepath[filepath.rindex("."):]
if en_or_decrypt.lower() == "e":
with open(outfilepath + "_Encrypted" + extension, "w") as outfile:
outfile.write("".join(new_text))
elif en_or_decrypt.lower() == "d":
with open(outfilepath + "_Decrypted" + extension, "w") as outfile:
outfile.write("".join(new_text))