-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathakiraCrypt.py
84 lines (51 loc) · 2.11 KB
/
akiraCrypt.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
import math
import hashlib
class akiraCryptography:
def __init__(self, key):
self.__k = key
def get_key(self):
return self.__k
def crypt(self, seq):
key = self.get_key()
key_value = int(hashlib.sha256(key.encode('utf-8')).hexdigest(), 16) % 10 ** 8
logkey = math.log(key_value)
lst = []
for n in str(logkey):
lst.append(n)
dec = lst[len(lst) - 2] + lst[len(lst) - 1]
dec_finale = int(dec) // math.log(int(dec))
pas = int(dec_finale)
liste_lettre = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
phrase_codee = []
phrase = seq.split()
for mot in phrase:
liste_mot = []
for lettre in mot:
i = liste_lettre.index(lettre)
if i + pas > 25:
i -= 26
liste_mot.append(liste_lettre[i + pas])
phrase_codee.append("".join(liste_mot))
print(" ".join(phrase_codee))
def decrypt(self, seq):
key = self.get_key()
key_value = int(hashlib.sha256(key.encode('utf-8')).hexdigest(), 16) % 10 ** 8
logkey = math.log(key_value)
lst = []
for n in str(logkey):
lst.append(n)
dec = lst[len(lst) - 2] + lst[len(lst) - 1]
dec_finale = int(dec) // math.log(int(dec))
pas = int(dec_finale)
liste_lettre = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
phrase_codee = []
phrase = seq.split()
for mot in phrase:
liste_mot = []
for lettre in mot:
i = liste_lettre.index(lettre)
if i - pas > 25:
i += 26
liste_mot.append(liste_lettre[i - pas])
phrase_codee.append("".join(liste_mot))
print(" ".join(phrase_codee))