Advertisement
Kira-kun

Function Captcha

Apr 7th, 2016
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. def generateCaptcha(this, words_count = 4, _pre_render = ""):
  2.         dicts = this.server.getCaptcha()
  3.         words = []
  4.         found = ""
  5.         if _pre_render == "":
  6.             while len(words) < words_count:
  7.                 randed = random.choice(dicts.keys())
  8.                 found += randed
  9.                 words += [randed]
  10.         else:
  11.             _pre_render = _pre_render.upper()
  12.             _pre_x = 0
  13.             while _pre_x < len(_pre_render):
  14.                 randed = _pre_render[_pre_x]
  15.                 found += randed
  16.                 words += [randed]
  17.                 _pre_x+=1
  18.                
  19.         last_y = 0
  20.         for wordy in words:
  21.             values = dicts[wordy]
  22.             if last_y < len(values.keys()):last_y = len(values.keys())
  23.         panel_x = 0
  24.         posy = 1
  25.         lines = []
  26.         while posy < last_y:
  27.             values = []
  28.             wp = 1
  29.             for word in words:
  30.                 wpy = posy
  31.                 wv = dicts[word]
  32.                 if wpy > len(wv.keys()):wpy = len(wv.keys())
  33.                 wlvs = wv[str(wpy)]
  34.                 cvp = 0
  35.                 if wp > 1:cvp = 1
  36.                 values += wlvs.split(",")[cvp:]
  37.                 wp+=1
  38.                
  39.             lines += [",".join(map(str, values))]
  40.             if panel_x < len(values):panel_x = len(values)
  41.             posy += 1
  42.            
  43.         c = byteArray()
  44.         panel_x += 2
  45.         c.writeShort(panel_x)
  46.         c.writeShort(last_y)
  47.         panel_tam = panel_x*last_y
  48.         c.writeShort(panel_tam)
  49.         for line in lines:
  50.             c.writeInt(0)
  51.             for vline in line.split(","):
  52.                 c.writeByte(int(vline))
  53.                 c.writeByte(0)
  54.                 c.writeByte(0)
  55.                 c.writeByte(0)
  56.             c.writeInt(0)
  57.            
  58.         while (len(c.toByteArray())-6)/4 < panel_tam:c.writeInt(0)
  59.        
  60.         this.sendData("\x1a\x14" + c.toByteArray(), [], True)
  61.         return found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement