F2FT_2Wplus2_Wplus2.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // by Boyang Wei
  2. package YaoGC;
  3. public class F2FT_2Wplus2_Wplus2 extends CompositeCircuit {
  4. private final int w;
  5. private int s1; // sigma
  6. private int s2;
  7. public F2FT_2Wplus2_Wplus2(int w, int s1, int s2) {
  8. super(2 * w + 2, w + 2, 6 * w + 4, "F2FT_" + (2 * w + 2) + "_" + w + 2);
  9. this.w = w;
  10. this.s1 = s1;
  11. this.s2 = s2;
  12. }
  13. protected void createSubCircuits() throws Exception {
  14. for (int i = 0; i < w; i++)
  15. subCircuits[i] = AND_2_1.newInstance();
  16. for (int i = w; i < 6 * w; i++)
  17. subCircuits[i] = XOR_2_1.newInstance();
  18. subCircuits[6 * w] = new FF10_Wplus1_Wplus1(w, true, s1);
  19. subCircuits[6 * w + 1] = new FF10_Wplus1_Wplus1(w, false, s1);
  20. subCircuits[6 * w + 2] = new FF10_Wplus1_Wplus1(w, true, s2);
  21. subCircuits[6 * w + 3] = new FF10_Wplus1_Wplus1(w, false, s2);
  22. s1 = s2 = 0;
  23. super.createSubCircuits();
  24. }
  25. protected void connectWires() throws Exception {
  26. inputWires[0].connectTo(subCircuits[6 * w].inputWires, 0);
  27. inputWires[1].connectTo(subCircuits[6 * w + 2].inputWires, 0);
  28. subCircuits[6 * w].outputWires[w].connectTo(
  29. subCircuits[6 * w + 1].inputWires, 0);
  30. subCircuits[6 * w + 2].outputWires[w].connectTo(
  31. subCircuits[6 * w + 3].inputWires, 0);
  32. for (int i = 0; i < w; i++) {
  33. inputWires[i + 2].connectTo(subCircuits[i].inputWires, 0);
  34. inputWires[i + w + 2].connectTo(subCircuits[i].inputWires, 1);
  35. inputWires[i + w + 2].connectTo(subCircuits[6 * w + 1].inputWires,
  36. i + 1);
  37. inputWires[i + w + 2].connectTo(subCircuits[i + 2 * w].inputWires,
  38. 1);
  39. subCircuits[i].outputWires[0].connectTo(
  40. subCircuits[6 * w].inputWires, i + 1);
  41. subCircuits[i].outputWires[0].connectTo(
  42. subCircuits[i + w].inputWires, 1);
  43. subCircuits[6 * w].outputWires[i].connectTo(
  44. subCircuits[i + w].inputWires, 0);
  45. subCircuits[6 * w].outputWires[i].connectTo(
  46. subCircuits[i + 3 * w].inputWires, 1);
  47. subCircuits[6 * w + 1].outputWires[i].connectTo(subCircuits[i + 2
  48. * w].inputWires, 0);
  49. subCircuits[6 * w + 1].outputWires[i].connectTo(subCircuits[i + 3
  50. * w].inputWires, 0);
  51. subCircuits[i + w].outputWires[0].connectTo(
  52. subCircuits[6 * w + 2].inputWires, i + 1);
  53. subCircuits[i + 2 * w].outputWires[0].connectTo(
  54. subCircuits[6 * w + 3].inputWires, i + 1);
  55. subCircuits[6 * w + 2].outputWires[i].connectTo(subCircuits[i + 4
  56. * w].inputWires, 0);
  57. subCircuits[6 * w + 3].outputWires[i].connectTo(subCircuits[i + 4
  58. * w].inputWires, 1);
  59. subCircuits[i + 3 * w].outputWires[0].connectTo(subCircuits[i + 5
  60. * w].inputWires, 1);
  61. subCircuits[i + 4 * w].outputWires[0].connectTo(subCircuits[i + 5
  62. * w].inputWires, 0);
  63. }
  64. }
  65. protected void defineOutputWires() {
  66. outputWires[0] = subCircuits[6 * w + 1].outputWires[w];
  67. outputWires[1] = subCircuits[6 * w + 3].outputWires[w];
  68. for (int i = 0; i < w; i++)
  69. outputWires[i + 2] = subCircuits[i + 5 * w].outputWires[0];
  70. }
  71. }