Advertisement
thepowderguy

Untitled

Sep 30th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1. from cv2 import *
  2.  
  3. import rsa
  4. import pygame
  5. import pygame.camera
  6. from PIL import Image
  7. from pygame.locals import *
  8. import datetime
  9.  
  10. #cv_im = cv.CreateImage((1300,700), cv.IPL_DEPTH_8U, 3)
  11. #pi = Image.fromstring("RGB", cv.GetSize(cv_im), cv_im.tostring())
  12. #pi.show()
  13.  
  14. locs = []
  15. avgs = []
  16. #for i
  17.  
  18. d = datetime.datetime.utcnow()
  19. epoch = datetime.datetime(1970,1,1)
  20. t = (d - epoch).total_seconds()
  21. time=int(t)
  22.  
  23. #pygame.init()
  24. #pygame.camera.init()
  25. #camlist = pygame.camera.list_cameras()
  26. #if camlist:
  27. #        cam = pygame.camera.Camera(camlist[0],(1280,720))
  28. #cam.start()
  29. #image = cam.get_image()
  30. #pil_string_image = pygame.image.tostring(image,"RGB",False)
  31. #im = Image.frombytes("RGB",(1280,720),pil_string_image)
  32. #im.show()
  33.  
  34.  
  35. im = Image.open("test.png").convert('RGB')
  36. WI = im.size[0]
  37. HE = im.size[1]
  38. for x in range(0, WI):
  39.     for y in range(0, HE):
  40.         r,g,b = im.getpixel((x, y))
  41.         if r > 128 and g < 128 and b > 128:
  42.             withindist = False
  43.             i = 0
  44.             for coord in locs:
  45.                 if (coord[0]-x)**2 + (coord[1]-y)**2 < 32*32:
  46.                     withindist = True
  47.                     break
  48.                 i += 1
  49.             if (not withindist):
  50.                 locs.append((x, y))
  51.                 avgs.append((x, y, 1))
  52.             else:
  53.                 n = avgs[i][2]
  54.                 xn = n/(n+1.0) * avgs[i][0] + (1.0 / (n+1.0)) * x
  55.                 yn = n/(n+1.0) * avgs[i][1] + (1.0 / (n+1.0)) * y
  56.                 zn = avgs[i][2] + 1
  57.                 avgs[i] = (xn,yn,zn)
  58.  
  59. sortout = sorted(avgs, key=lambda c: c[1])
  60.  
  61. TL = (0,0,0)
  62. TR = (0,0,0)
  63. BL = (0,0,0)
  64. BR = (0,0,0)
  65.  
  66. if (sortout[0][0] < sortout[1][0]):
  67.     TL = sortout[0]
  68.     TR = sortout[1]
  69. else:
  70.     TL = sortout[1]
  71.     TR = sortout[0]
  72.  
  73. if (sortout[2][0] < sortout[3][0]):
  74.     BL = sortout[2]
  75.     BR = sortout[3]
  76. else:  
  77.     BL = sortout[3]
  78.     BR = sortout[2]
  79.  
  80. print(TL)
  81. print(TR)
  82. print(BL)
  83. print(BR)
  84.  
  85. def add(v1, v2):
  86.     return (v1[0]+v2[0], v1[1]+v2[1])
  87.  
  88. def sub(v1, v2):
  89.     return (v1[0]-v2[0], v1[1]-v2[1])
  90.  
  91. def mul(v1, sc):
  92.     return (v1[0]*sc, v1[1]*sc)
  93.  
  94. yaxis = sub(BL, TL)
  95. xaxis = sub(TR, TL)
  96.  
  97. crypto = ""
  98. signature = ""
  99.  
  100. for y in range(0, 32):
  101.     for xt in range(0, 4):
  102.         total = 0
  103.         for xtt in range(0, 8):
  104.             x = xt*8 + xtt
  105.             xn = (x+1.0)/(32.0+1.0)
  106.             yn = (y+1.0)/(32.0+1.0)
  107.             finalloc = add(TL, add(mul(xaxis, xn), mul(yaxis, yn)))
  108.             r,g,b = im.getpixel((int(finalloc[0]), int(finalloc[1])))
  109.             im.putpixel((int(finalloc[0]), int(finalloc[1])), 0x00FF00)
  110.             if (r+g+b < 300):
  111.                 data = 1
  112.             else:
  113.                 data = 0
  114.             total += data*(2**(xtt))
  115.         if (y < 16):
  116.             signature += chr(total)
  117.         else:
  118.             crypto += chr(total)
  119. print(signature)
  120. print(crypto)
  121.  
  122.  
  123. im.show()
  124.  
  125. message = rsa.decrypt(crypto, privkey)
  126. message = "a"
  127. signature = "a"
  128. (pubkey, privkey) = rsa.newkeys(512)
  129.  
  130.  
  131. if(rsa.verify(message, signature, pubkey)):
  132.     print("YES"+ message)
  133. else:
  134.     print("NO")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement