-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirstsetup.py
More file actions
108 lines (88 loc) · 2.94 KB
/
firstsetup.py
File metadata and controls
108 lines (88 loc) · 2.94 KB
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
from cryptography.fernet import Fernet
import time, re, os, time
# The setup of making your chatapp password
def passwordsetup():
while True:
time.sleep(1)
print(">> Requirements: Lenght 8, Number, Capital Letter")
print(">> Enter your Password:")
password = input("> ")
if len(password) < 8:
print(">> Make sure your password is at lest 8 letters")
elif re.search('[0-9]',password) is None:
print(">> Make sure your password has a number in it")
elif re.search('[A-Z]',password) is None:
print(">> Make sure your password has a capital letter in it")
else:
print(">> Retype your password:")
retypepassword = input("> ")
if retypepassword == password :
retypepassword = "Nil"
del retypepassword
print(">> Password check complete")
print(">>> Setting up Chatapp!")
print(">>> This may take a while")
return password
elif retypepassword != password :
retypepassword = "Nil"
del retypepassword
password = "Nil"
del password
print(">> Try agian!")
passwordsetup()
# The encryption procces of the key using your password
def encrypter(pword, key):
encrykey = []
for i, c in enumerate(key):
pword_c = ord(pword[i % len(pword)])
enc_c = ord(c)
encrykey.append(chr((enc_c + pword_c) % 127))
return ''.join(encrykey)
pword = passwordsetup()
# Deleting all info about this/these variabel('s) after used
password = "Nil"
del password
# key generation + bytes -> string
bytekey = Fernet.generate_key()
decrykey = bytekey.decode('UTF-8')
print(bytekey)
# Deleting all info about this/these variabel('s) after used
bytekey = "Nil"
del bytekey
# using the generated key
fernet = Fernet(decrykey)
# Generating a encrypted key
encrykey = encrypter(pword, decrykey)
print(decrykey)
print(encrykey)
# Deleting all info about this/these variabel('s) after used
pword = "Nil"
del pword
decrykey = "Nil"
del decrykey
# Writing the encrypted key in a file
with open('file.key', 'w') as file:
file.write(encrykey)
# Deleting all info about this/these variabel('s) after used
encrykey = 'Nil'
del encrykey
time.sleep(1)
open('info.csv', 'wb')
# opening the original file bytes to encrypt
with open('info.csv', 'rb') as file:
original = file.read()
# encrypting the file bytes
encryfile = fernet.encrypt(original)
# Deleting all info about this/these variabel('s) after used
fernet = "Nil"
del fernet
# Deleting all info about this/these variabel('s) after used
original = "Nil"
del original
# opening the file in write mode and
# writing the encrypted bytes
with open('info.csv', 'wb') as encrypted_file:
encrypted_file.write(encryfile)
# Remove any information about this/these variable('s) on the memory
encryfile = "Nil"
del encryfile