padra.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import json
  2. import os
  3. import time
  4. class padra():
  5. def __init__(self,len):
  6. self.len = len
  7. print("added",self.len)
  8. def toSend(self,x):
  9. j = json.dumps(x)
  10. l = self.len - len(str(len(j)))
  11. return "0000"[0:l]+str(len(j))+j
  12. def toJson(self,x):
  13. print( x)
  14. return json.loads(x)
  15. # user
  16. def xor(self,o,key,data):
  17. print("startetd")
  18. o0data= {
  19. "function":"xor",
  20. "players_number":"3",
  21. "player":"0",
  22. "ip":"192.168.178.105",
  23. "data":"",
  24. }
  25. o[0].send(self.toSend(o0data))
  26. o1data= {
  27. "function":"xor",
  28. "players_number":"3",
  29. "player":"1",
  30. "ip":"192.168.178.105",
  31. "data":key,
  32. }
  33. o[1].send(self.toSend(o1data))
  34. o2data= {
  35. "function":"xor",
  36. "players_number":"3",
  37. "player":"2",
  38. "ip":"192.168.178.105",
  39. "data":data
  40. }
  41. o[2].send(self.toSend(o2data))
  42. def aes(self,o,key,data):
  43. print("startetd")
  44. o0data= {
  45. "function":"aes",
  46. "players_number":"3",
  47. "player":"0",
  48. "ip":"192.168.178.105",
  49. "data":"",
  50. }
  51. o[0].send(self.toSend(o0data))
  52. o1data= {
  53. "function":"aes",
  54. "players_number":"3",
  55. "player":"1",
  56. "ip":"192.168.178.105",
  57. "data":key,
  58. }
  59. o[1].send(self.toSend(o1data))
  60. o2data= {
  61. "function":"aes",
  62. "players_number":"3",
  63. "player":"2",
  64. "ip":"192.168.178.105",
  65. "data":data
  66. }
  67. o[2].send(self.toSend(o2data))
  68. print("Data send from USER")
  69. # oracle
  70. def parse(self,message):
  71. data = json.loads(message)
  72. print(data)
  73. function = data["function"]
  74. if(function == "aes"):
  75. self.aesOracle(data["players_number"],data["player"],data["ip"],data["data"])
  76. elif(function == "xor"):
  77. self.xorOracle(data["players_number"],data["player"],data["ip"],data["data"])
  78. def aesOracle(self,players_number,player,ip,data):
  79. player=int(player)
  80. players_number=int(players_number)
  81. time.sleep(player*10)
  82. line = " "
  83. t1= "echo "+ data + " > gf2n_vals.in"
  84. t2= "./gen_input_f2n.x"
  85. t3= "mv ./gf2n_vals.out ./Player-Data/Private-Input-"+str(player)
  86. t4= "./mascot-party.x "+str(player)+" aes_m -pn 12598 -h "+ip+" -N "+str(players_number)
  87. handle = (os.system("ls"))
  88. print (handle)
  89. handle = (os.system("cd .."))
  90. print (handle)
  91. handle = (os.system("ls"))
  92. print (handle)
  93. handle = (os.system(t1))
  94. print (line)
  95. handle = (os.system(t2))
  96. print (line)
  97. handle = (os.system(t3))
  98. print (line)
  99. handle = (os.system(t4))
  100. print (line)
  101. def xorOracle(self,players_number,player,ip,data):
  102. player=int(player)
  103. print(player)
  104. players_number=int(players_number)
  105. time.sleep(player*10)
  106. line = " "
  107. if player != 0:
  108. t1= "echo 1 "+ data + " > gf2n_vals.in"
  109. handle = (os.system(t1))
  110. print (line)
  111. if player != 0:
  112. handle = (os.system("./gen_input_f2n.x"))
  113. print (line)
  114. if player != 0:
  115. handle = (os.system("mv ./gf2n_vals.out ./Player-Data/Private-Input-"+str(player)))
  116. print (line)
  117. print("player " + str(player) )
  118. t4= "./mascot-party.x "+str(player)+" xor -pn 12598 -h "+ip+" -N "+str(players_number)
  119. handle = (os.system(t4))
  120. print (line)