How to fix the error probability plot in Python for MIM and PNS attacks?

  • Topic: Python 
  • Thread starter Nur Ziadah
  • Start date
  • Tags Tags
    Convert Python
4 replies · 5K views · last reply
Nur Ziadah
Messages
34
Reaction score
3
I have several equations and need to convert it into Python. The problem is that I tried to plot a graph according to the equation. However, the graph that I get is not the same as the original one.

In the paper, the equation of error probability for MIM attack is given by:

First Image
Equation 8.4: P_e^Auth,normal(t, N) equals a double integral over dphi1 and dphi1-tilde of P(phi1-tilde | phi1, tN) P(phi1), over the region |phi1 - phi1-tilde| > pi/4.

Second Image
Equation 8.5: P_e^Auth,normal(t,N) approximately 2/(pi(1-e^-N)) times integrals over phi_1 from pi/4 to pi/2 and 0 to pi/4 of sums of P_1 terms, equal to 4/pi times integral from 0 to pi/4 of (1 - e^(tN sin^2 phi_1))/(1 - e^(tN)) d phi_1, which equals (e^(tN/2)[I_0(tN/2) - L_0(tN/2)] - 1)/(e^(tN) - 1).

The equation to calculate the error probability of PNS attack is given by:
Equation 8.1: Pe(N1, N2) equals the integral over region S of dφ̂1 dφ̂2 dφ1 dφ2 times P(φ1)P1(φ̂1|φ1, N1)P(φ2)P2(φ̂2|φ2, N2).

Where the region condition satisfied:
Inequality: absolute value of (phi2 hat minus phi1 hat) minus (phi2 minus phi1) is greater than pi over 4.

The error probability of PNS attack should be plotted like this:
Line graph of error probability P_e(N1, N2) against mean photon number N from 0 to 20, with four curves: N1 = N2 = N/2 falls fastest to about 0.02; t = 0.5 and t = 0.1 curves fall more slowly; t = 0.9 curve falls least, to about 0.21.

My question: How to insert equation 8.1 into equation 8.5?

This is my python code according to equation 8.5:

Python:
import matplotlib.pyplot as plt
import math
import numpy as np
from scipy.special import iv,modstruvex=[0, 5, 10, 15, 20]
t= 0.9
x = np.array(x)
y = (np.exp(x*t/2)*(iv(0, x*t/2) - modstruve(0,x*t/2))-1)/(np.exp(x*t/2-1))                                           

plt.plot(x, y, label='Normal')
plt.xlabel('Mean photon number N')
plt.ylabel('Error probabiity')
plt.scatter(x,y)
plt.title('N/2')
plt.ylim([0, 0.5])
plt.legend()
plt.show()

Please help me regarding this matter.

Thank you.
 
Attachments
  • Equation 8.4: P_e^Auth,normal(t, N) equals a double integral over dphi1 and dphi1-tilde of P(phi1-tilde | phi1, tN) P(phi1), over the region |phi1 - phi1-tilde| > pi/4.
    jlPMh.png
    3.3 KB · Views: 1,222
  • Equation 8.5: P_e^Auth,normal(t,N) approximately 2/(pi(1-e^-N)) times integrals over phi_1 from pi/4 to pi/2 and 0 to pi/4 of sums of P_1 terms, equal to 4/pi times integral from 0 to pi/4 of (1 - e^(tN sin^2 phi_1))/(1 - e^(tN)) d phi_1, which equals (e^(tN/2)[I_0(tN/2) - L_0(tN/2)] - 1)/(e^(tN) - 1).
    h99h4.png
    9.7 KB · Views: 1,286
  • Equation 8.1: Pe(N1, N2) equals the integral over region S of dφ̂1 dφ̂2 dφ1 dφ2 times P(φ1)P1(φ̂1|φ1, N1)P(φ2)P2(φ̂2|φ2, N2).
    7CsYR.png
    3.9 KB · Views: 1,226
  • Inequality: absolute value of (phi2 hat minus phi1 hat) minus (phi2 minus phi1) is greater than pi over 4.
    0Bxa3.png
    1.5 KB · Views: 1,121
  • Line graph of error probability P_e(N1, N2) against mean photon number N from 0 to 20, with four curves: N1 = N2 = N/2 falls fastest to about 0.02; t = 0.5 and t = 0.1 curves fall more slowly; t = 0.9 curve falls least, to about 0.21.
    1IwAa.png
    18.6 KB · Views: 1,216
When x=0 then N=0 hence the denominator is zero and so you are dividing zero according to the equation.

In your code, you misplaced the last paren. it should look like this:

Python:
y = (   np.exp(x*t/2) * (iv(0,x*t/2) - modstruve(0,x*t/2)) - 1   )  /  (np.exp(x*t/2) - 1)

This code now gives a runtime divide error at zero but the curve looks more like what you want.