This repository was archived by the owner on Jun 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkeystream.py
More file actions
53 lines (41 loc) · 1.26 KB
/
keystream.py
File metadata and controls
53 lines (41 loc) · 1.26 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
import gen_bin
from random import randint
class keystream :
def __init__(self) -> None :
self.U = self.__key_gen()
self.IV = gen_bin.hek_conv(randint(1, 15))
self.lfsr = self.__lfsr_sys(self.U)
def __key_gen(self) :
temp = randint(1, 255)
temp += randint(1, 255)
temp = gen_bin.bin_conv(temp)
if len(temp) < 16 :
tmp = ""
for i in range(16-len(temp)) :
tmp += "0"
temp = tmp+temp
return temp
def __gen_lfsr(self, kunci) :
sway = int(kunci[len(kunci)-1]) ^ int(kunci[0])
kunci = str(sway)+kunci[:len(kunci)-1]
return kunci
def __pecah(self, kata) :
temp = ""
i = 0
j = 4
while j <= len(kata) :
temp += gen_bin.hek_conv(gen_bin.bin_conv(kata[i:j]))
i += 4
j += 4
return temp
def __lfsr_sys(self, kunci) :
temp = ""
temp += kunci[len(kunci)-1]
kunci = self.__gen_lfsr(kunci)
pegang = kunci
i = 0
while kunci != pegang or i == 0 :
temp += kunci[len(kunci)-1]
kunci = self.__gen_lfsr(kunci)
i += 1
return self.__pecah(temp)