标题: 安全通论作业一(1),系列篇 [打印本页] 作者: 八卦阵 时间: 2024-6-15 02:17 标题: 安全通论作业一(1),系列篇 ]
C = max[I(X, Z)]
C=max[I(X,Z)](这里最大值是针对 X 为所有大概的二元离散随机变量来计算的)。
在此处一对一的信道中,其容量
C
=
m
a
x
0
<
a
,
p
<
1
[
I
(
X
,
Z
)
]
C = max_{0<a,p<1}[I(X,Z)]
C=max0<a,p<1[I(X,Z)],这里的最大值是对仅仅两个变量 a 和 p 在条件 0 < a,p < 1 下之取的,也就是说 攻击信道容量 C,实在是 q 的函数。
攻击信道容量的数值分析
根据攻击信道容量公式
C
=
m
a
x
0
<
a
,
p
<
1
[
I
(
X
,
Z
)
]
=
m
a
x
0
<
a
,
p
<
1
[
(
1
def get_i(a, p ,q):
c1 = 1 + a - p - q
c2 = q - a
c3 = p - a
c4 = 1 + 2 * a - p - q
c5 = p + q - 2 * a
i1 = c1 * np.log(c1 / ((1 - p) * c4))
i2 = c2 * np.log(c2 / ((1 - p) * c5))
i3 = a * np.log(a / (p * c4))
i4 = c3 * np.log(c3 / (p * c5))
i = i1 + i2 + i3 + i4
return i
def get_max_i(i):
def get_max_i(a, p ,q):
i = get_i(a, p ,q)
i = np.nan_to_num(i)
max_i = np.max(i)
print(max_i)
print(i)
return max_i
此中 get_i 函数是根据公式 I(X, Z) 计算互信息,get_max_i 函数是根据
C
=
m
a
x
0
<
a
,
p
<
1
[
I
(
X
,
Z
)
]
C = max_{0<a,p<1}[I(X,Z)]
C=max0<a,p<1[I(X,Z)] 计算信道容量,即最大的互信息。画出攻击信道容量的数值分析图像如下:
import numpy as np
import matplotlib.pyplot as plt
_p = np.arange(0.01, 1.00, 0.01)
_q = np.arange(0.01, 1.00, 0.01)
Meshgrid for 2D array creation
p, q = np.meshgrid(_p, _q)
2D array outer product
a = np.outer(_p, _q)
Compute mutual information
def get_i(a, p ,q):
c1 = 1 + a - p - q
c2 = q - a
c4 = p - a
c5 = 1 + 2 * a - p - q
c6 = p + q - 2 * a
i1 = c1 * np.log(c1 / ((1 - p) * c5))
i2 = c2 * np.log(c2 / ((1 - p) * c6))
i3 = a * np.log(a / (p * c5))
i4 = c4 * np.log(c4 / (p * c6))
i = i1 + i2 + i3 + i4
return i
i = get_i(a, p ,q)
Plotting
fig = plt.figure()
ax = fig.add_subplot(111, projection=‘3d’)
ax.plot_surface(p, q, i, cmap=‘jet’)
Axis labels
ax.set_xlabel(‘p’)
ax.set_ylabel(‘q’)
ax.set_zlabel(‘I(X,Z)’)
Title
ax.set_title(‘Image of I(X,Z) when a=pq’)
plt.show()
ax.set_xlabel(‘q’)
ax.set_ylabel(‘max I(X,Z)’)
Title
ax.set_title(‘Image of C = max I(X,Z) vs q’)
plt.show()
plt.savefig(‘Cvsq.png’, dpi=100)
print(q_range[np.argmin(max_i)], np.min(max_i))
print(q_range[np.argmax(max_i)], np.max(max_i))
固定 q 时,互信息与 p 和 a 的关系
以下为 q = 0.1 到 q = 0.9 时, 互信息 I(X, Z) 与 p 和 a 的关系。(代码见 hw1-Ivsap.py)
import numpy as np
import matplotlib.pyplot as plt
q = 0.1
Compute mutual information
def get_i(a, p ,q):
c1 = 1 + a - p - q
c2 = q - a
c3 = p - a
c4 = 1 + 2 * a - p - q
c5 = p + q - 2 * a
i1 = c1 * np.log(c1 / ((1 - p) * c4))
i2 = c2 * np.log(c2 / ((1 - p) * c5))
i3 = a * np.log(a / (p * c4))
i4 = c3 * np.log(c3 / (p * c5))
i = i1 + i2 + i3 + i4
return i
def get_max_i(i):
def get_max_i(a, p ,q):
i = get_i(a, p ,q)
i = np.nan_to_num(i) 自我先容一下,小编13年上海交大结业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。 深知大多数网络安全工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技能故步自封! 因此收集整理了一份《2024年网络安全全套学习资料》,初志也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋侪。