By embedding a line defect in a two-dimensional photonic crystal and using linear interference effect and waveguide coupling, an XNOR gate and NAND gate structure based on two-dimensional photonic crystal is designed. The band structure of the two-dimensional photonic crystal is analyzed by the plane wave expansion method. The finite-difference time-domain method and the linear interference effect are used to simulate the stable electric field diagram and the normalized power of the XNOR gate and the NAND gate on the Rsoft platform. The simulation results show that the designed XNOR gate has a contrast of 29.5 dB, a response time of 0.073 ps, and a data transmission rate of 13.7 Tbit / s. The designed NAND gate has a contrast of up to 24.15 dB, a response time of 0.08 ps, and a data transmission rate of 12.5 Tbit / s. These parameters indicate that the designed structure has high contrast, short response time and fast data transmission rate.