-
Notifications
You must be signed in to change notification settings - Fork 0
/
rolling code.py
56 lines (41 loc) · 1.43 KB
/
rolling code.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
# from February 8 2017 to
# Malibu, California
# San Diego, California
# source patent US 6980655
# receiving rolling code
# reverse order of binary digits -> zero the most significant digit -> set initial trinary
# rolling code to zero -> subtract next highest power of three from rolling code ->
# result is bigger than zero -> increment next most significant digit of binary rolling code
# result is smaller or equal to zero -> add next highest power of three to rolling code ->
# next highest power of three
# making the rolling code
#
# Python 3.5 code
import numpy as np
import random
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from numpy import *
def run(total_bit):
each_digit = 0
rolling_code = []
for i in range(total_bit):
if random.random() > 0.5:
each_digit = random.randint(65, 91)
else:
each_digit = random.randint(97, 123)
rolling_code.append(chr(each_digit))
return rolling_code
def main():
total_bit = 40;
total_num = 40;
rolling_code = run(total_bit)
# print("The rolling code is %s" % rolling_code)
group = [run(total_bit) for i in range(total_num)]
# print(type(group), len(group), len(group[0]))
group_2D = np.asarray(group).reshape(total_bit, total_num)
print(group_2D)
print(type(group_2D[0, 0]))
# Change character to RGB color for visualization
if __name__ == '__main__':
main()