Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from cv2 import *
- import rsa
- import pygame
- import pygame.camera
- from PIL import Image
- from pygame.locals import *
- import datetime
- #cv_im = cv.CreateImage((1300,700), cv.IPL_DEPTH_8U, 3)
- #pi = Image.fromstring("RGB", cv.GetSize(cv_im), cv_im.tostring())
- #pi.show()
- locs = []
- avgs = []
- #for i
- d = datetime.datetime.utcnow()
- epoch = datetime.datetime(1970,1,1)
- t = (d - epoch).total_seconds()
- time=int(t)
- #pygame.init()
- #pygame.camera.init()
- #camlist = pygame.camera.list_cameras()
- #if camlist:
- # cam = pygame.camera.Camera(camlist[0],(1280,720))
- #cam.start()
- #image = cam.get_image()
- #pil_string_image = pygame.image.tostring(image,"RGB",False)
- #im = Image.frombytes("RGB",(1280,720),pil_string_image)
- #im.show()
- im = Image.open("test.png").convert('RGB')
- WI = im.size[0]
- HE = im.size[1]
- for x in range(0, WI):
- for y in range(0, HE):
- r,g,b = im.getpixel((x, y))
- if r > 128 and g < 128 and b > 128:
- withindist = False
- i = 0
- for coord in locs:
- if (coord[0]-x)**2 + (coord[1]-y)**2 < 32*32:
- withindist = True
- break
- i += 1
- if (not withindist):
- locs.append((x, y))
- avgs.append((x, y, 1))
- else:
- n = avgs[i][2]
- xn = n/(n+1.0) * avgs[i][0] + (1.0 / (n+1.0)) * x
- yn = n/(n+1.0) * avgs[i][1] + (1.0 / (n+1.0)) * y
- zn = avgs[i][2] + 1
- avgs[i] = (xn,yn,zn)
- sortout = sorted(avgs, key=lambda c: c[1])
- TL = (0,0,0)
- TR = (0,0,0)
- BL = (0,0,0)
- BR = (0,0,0)
- if (sortout[0][0] < sortout[1][0]):
- TL = sortout[0]
- TR = sortout[1]
- else:
- TL = sortout[1]
- TR = sortout[0]
- if (sortout[2][0] < sortout[3][0]):
- BL = sortout[2]
- BR = sortout[3]
- else:
- BL = sortout[3]
- BR = sortout[2]
- print(TL)
- print(TR)
- print(BL)
- print(BR)
- def add(v1, v2):
- return (v1[0]+v2[0], v1[1]+v2[1])
- def sub(v1, v2):
- return (v1[0]-v2[0], v1[1]-v2[1])
- def mul(v1, sc):
- return (v1[0]*sc, v1[1]*sc)
- yaxis = sub(BL, TL)
- xaxis = sub(TR, TL)
- crypto = ""
- signature = ""
- for y in range(0, 32):
- for xt in range(0, 4):
- total = 0
- for xtt in range(0, 8):
- x = xt*8 + xtt
- xn = (x+1.0)/(32.0+1.0)
- yn = (y+1.0)/(32.0+1.0)
- finalloc = add(TL, add(mul(xaxis, xn), mul(yaxis, yn)))
- r,g,b = im.getpixel((int(finalloc[0]), int(finalloc[1])))
- im.putpixel((int(finalloc[0]), int(finalloc[1])), 0x00FF00)
- if (r+g+b < 300):
- data = 1
- else:
- data = 0
- total += data*(2**(xtt))
- if (y < 16):
- signature += chr(total)
- else:
- crypto += chr(total)
- print(signature)
- print(crypto)
- im.show()
- message = rsa.decrypt(crypto, privkey)
- message = "a"
- signature = "a"
- (pubkey, privkey) = rsa.newkeys(512)
- if(rsa.verify(message, signature, pubkey)):
- print("YES"+ message)
- else:
- print("NO")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement