-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.py
48 lines (48 loc) · 1.93 KB
/
basic.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
import ast
from datetime import datetime
import time
def bubbleSort(array_to_sort):
array_length = len(array_to_sort)
for i in range(array_length):
for j in range(0, array_length - i - 1):
current = array_to_sort[j].split()
check = array_to_sort[j + 1].split()
if datetime.strptime(current[0] + " " + current[1], '%d/%m/%Y %H:%M') > datetime.strptime(check[0] + " " + check[1], '%d/%m/%Y %H:%M'):
array_to_sort[j], array_to_sort[j + 1] = array_to_sort[j + 1], array_to_sort[j]
return array_to_sort
communication_log = open("log.txt", "r")
communication_transmissions = ast.literal_eval(communication_log.read())
message_list = []
decryption_start = time.time()
for message in communication_transmissions:
factor = []
message_output = ""
split_list = []
for i in range(2, message[0] + 1):
if(message[0] % i == 0):
prime_flag = 1
for j in range(2, (i // 2 + 1)):
if(i % j == 0):
prime_flag = 0
break
if (prime_flag == 1):
factor.append(i)
length = (factor[0] - 1) * (factor[1] - 1)
for i in range(length, length * 3):
if((i * message[1]) % (length) == 1):
decryptionkey = i
break
split_length = len(str(message[0]))
for i in range(0, len(message[2]), split_length):
split_list.append(message[2][i:i + split_length] )
for character in split_list:
decrypt = chr((int(character) ** int(decryptionkey)) % int(message[0]))
message_output = message_output + decrypt
message_list.append(message_output + " - Private Key: " + str(decryptionkey))
decryption_end = time.time()
sort_start = time.time()
for message in (bubbleSort(message_list)):
print(message)
sort_end = time.time()
print("Decryption Total Time:", decryption_end - decryption_start)
print("Sort Total Time:", sort_end - sort_start)