-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (62 loc) · 1.87 KB
/
Copy pathmain.py
File metadata and controls
76 lines (62 loc) · 1.87 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
import cv2
#features to be included:
#true random number generator
#pseudo random number generator
#data encryption
#data decryption
#file encryption
#file decryption
#true random number generator
def true_randint(lower, upper, method = None):
if method == None:
#raise error
raise Exception("No method found")
if lower >= upper:
raise Exception("Range of numbers is wrong")
if method == 'camera':
#get frame
vid = cv2.VideoCapture(0)
ret, frame = vid.read()
vid.release()
#choose central pixel
central_pixel = frame[int(len(frame)/2)][0]
# print(central_pixel)
list_of_numbers = []
for _ in range(3):
m = 1
for value in central_pixel:
m *= value
list_of_numbers.append(m)
list_of_numbers.sort()
upper_rng = list_of_numbers[-1]
lower_rng = list_of_numbers[0]
rng = list_of_numbers[1]
dif_to_base = ((rng-lower_rng) * (upper-lower)/(upper_rng-lower_rng))
return lower + dif_to_base
elif method == 'mic':
#use mic for generation
return number
else:
raise Exception("Invalid method")
#data encryption
def encrypt(text, method = "caesar_cipher", shift = None):
#caesar cipher
if method == "caesar_cipher":
ret = ""
for alpha in text:
if shift == None:
shift = 3
ret += chr(ord(alpha)+shift)
return ret
#data decryption
def decrypt(text, method = "caesar_cipher", shift = None):
if method == "caesar_cipher":
ret = ""
for alpha in text:
if shift == None:
shift = 3
ret += chr(ord(alpha)-shift)
return ret
if __name__ == "__main__":
print(encrypt("this is a test!"))
print(decrypt("wklv#lv#d#whvw$"))