AdditionalPylons

luart decryptor

Nov 28th, 2025
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.05 KB | None | 0 0
  1. local ui = require "ui"
  2. require "canvas"
  3. local crypto = require "crypto"
  4.  
  5. local function isdirectory(path)
  6.   return xpcall(function()
  7.       sys.Directory(path)
  8.       return true
  9.     end, function() return false end)
  10. end
  11. local function encode(filename,key) -- algo: aes256
  12.   if isdirectory(filename) then
  13.     for entry in each(sys.Directory(filename)) do
  14.       encode(filename.."\\"..entry.name,key)
  15.     end
  16.     return
  17.   end
  18.   local cipher = crypto.Cipher("aes256", key)
  19.   local f = sys.File(filename)
  20.   cipher:encrypt(f:open("read","binary"):read())
  21.   f:close()
  22.   f:open("write","binary")
  23.   f:write(cipher.encrypted)
  24.   f:close()
  25. end
  26. local function decode(filename,key)
  27.   if isdirectory(filename) then
  28.     for entry in each(sys.Directory(filename)) do
  29.       decode(filename.."\\"..entry.name,key)
  30.     end
  31.     return
  32.   end
  33.   local cipher = crypto.Cipher("aes256", key)
  34.   local f = sys.File(filename)
  35.   cipher:decrypt(f:open("read","binary"):read())
  36.   f:close()
  37.   f:open("write","binary")
  38.   f:write(cipher.decrypted)
  39.   f:close()
  40. end
  41. local win = ui.Window("Decryptor","dialog",600,600)
  42.  
  43. local directory_l = {}
  44. local directory
  45. for i in each(sys.Directory(".")) do
  46.   if isdirectory(i.fullpath) then
  47.     table.insert(directory_l,i)
  48.   end
  49. end
  50. if #directory_l==1 then
  51.   directory = directory_l[1]
  52. else
  53.   directory = ui.dirdialog("Choose directory to decode:")
  54. end
  55. if directory == nil then os.exit() end
  56. directory = directory.fullpath
  57.  
  58. win:status("Press Enter to use the password. Directory: "..directory)
  59.  
  60. local canvas = ui.Canvas(win,0,0,win.width,win.height)
  61. local patterns = {} -- each pattern is a table of unit points
  62. local h_scale,v_scale = 7,14/math.sqrt(3)
  63. local hex_r = h_scale
  64. local scale = 10
  65. local top_y,left_x = 0,0
  66. local m_x,m_y = 0,0
  67. local is_drawing = false
  68. local draw_color = 0xffffffff
  69. local hash = nil
  70.  
  71. local function round(n)
  72.   return math.floor(n+0.5)
  73. end
  74.  
  75. local function snap_to_grid_unit(x,y) -- return two values in grid units
  76.   local closest_y = round((y-top_y)/v_scale/scale)
  77.   local closest_x = round(((x-left_x+(closest_y&1)*h_scale)/h_scale)/scale) -- garbage
  78.   return closest_x,closest_y
  79. end
  80. local function unit_to_grid(x,y)     -- change units to pixels
  81.   return (x*h_scale-(y&1)*h_scale/2)*scale+left_x, y*v_scale*scale+top_y
  82. end
  83. local function snap_to_grid(x,y)      -- return two values in pixels
  84.   ux,uy = snap_to_grid_unit(x,y)
  85.   return unit_to_grid(ux,uy)
  86. end
  87.  
  88. local function getdirection(p1,p2)
  89.   local x1,y1 = unit_to_grid(table.unpack(p1))
  90.   local x2,y2 = unit_to_grid(table.unpack(p2))
  91.   if x1<x2 and y1==y2 then return 1 end
  92.   if x1<x2 and y1<y2 then return 2 end
  93.   if x1>x2 and y1<y2 then return 3 end
  94.   if x1>x2 and y1==y2 then return 4 end
  95.   if x1>x2 and y1>y2 then return 5 end
  96.   if x1<x2 and y1>y2 then return 6 end
  97.   if x1==x2 and y1>y2 then return 7 end
  98.   if x1==x2 and y1<y2 then return 8 end
  99. end
  100. local function points_to_hash()
  101.   local bytes = 0
  102.   for i=1,#patterns do
  103.     bytes=bytes+#patterns[i]+1
  104.   end
  105.   local buffer = sys.Buffer(bytes)
  106.   local bufferptr = 1
  107.   for i=1,#patterns do
  108.     for j=1,#patterns[i]-1 do
  109.       n = getdirection(patterns[i][j],patterns[i][j+1])
  110.       buffer[bufferptr] = n
  111.       bufferptr=bufferptr+1
  112.     end
  113.     buffer[bufferptr] = 0xff
  114.     bufferptr=bufferptr+1
  115.   end
  116.   return crypto.hash("sha256",buffer)
  117. end
  118.  
  119. function win:onResize()
  120.   canvas.width,canvas.height = win.width,win.height
  121. end
  122.  
  123. local function points_equal(p1,p2)
  124.   return p1[1]==p2[1] and p1[2]==p2[2]
  125. end
  126. function canvas:onHover(x,y)
  127.   m_x,m_y = x/ui.dpi,y/ui.dpi
  128.   if not is_drawing then return end
  129.  
  130.   local point = {snap_to_grid_unit(m_x,m_y)}
  131.   cl_x,cl_y = unit_to_grid(table.unpack(point))
  132.   local last_pattern = patterns[#patterns]
  133.   if last_pattern==nil then return end
  134.   if math.abs(cl_x-m_x)<h_scale*scale/5 and math.abs(cl_y-m_y)<v_scale*scale/5 then
  135.     if #last_pattern>1 and points_equal(point,last_pattern[#last_pattern-1]) then
  136.       table.remove(last_pattern)
  137.     elseif not points_equal(point,last_pattern[#last_pattern]) then
  138.       last_pattern[#last_pattern+1] = {snap_to_grid_unit(m_x,m_y)}
  139.     end
  140.   end
  141. end
  142. function canvas:onMouseDown(x,y)
  143.   patterns[#patterns+1] = {{snap_to_grid_unit(x/ui.dpi,y/ui.dpi)}} -- add a 2d array
  144.   is_drawing = true
  145. end
  146. function canvas:onMouseUp(x,y)
  147.   if not is_drawing then return end
  148.   is_drawing = false
  149.   local last = patterns[#patterns]
  150.   if last == nil then return end
  151.   if #last == 1 then patterns[#patterns]=nil end
  152. end
  153. function canvas:onContext()
  154.   table.remove(patterns)
  155.   is_drawing = false
  156. end
  157. function canvas:onPaint()
  158.   canvas:begin()
  159.   canvas:clear(0)
  160.   for i=1,canvas.width/h_scale/scale do
  161.     for j=1,canvas.height/v_scale/scale do
  162.       canvas:fillcircle(left_x+i*h_scale*scale - h_scale*scale/2*(j&1),top_y+j*v_scale*scale,3,0x337788ff)
  163.     end
  164.   end
  165.   for i=1,#patterns do
  166.     for j=1,#patterns[i]-1 do
  167.       local p1_x,p1_y = unit_to_grid(table.unpack(patterns[i][j]))
  168.       local p2_x,p2_y = unit_to_grid(table.unpack(patterns[i][j+1]))
  169.       canvas:line(p1_x,p1_y,p2_x,p2_y,draw_color,3)
  170.     end
  171.   end
  172.   if is_drawing then
  173.     local last_pattern = patterns[#patterns]
  174.     local p_x,p_y = unit_to_grid(table.unpack(last_pattern[#last_pattern]))
  175.     canvas:line(p_x,p_y,m_x,m_y,draw_color,3)
  176.   end
  177.   canvas:flip()
  178. end
  179. function win:onKey(k)
  180.   if k=="W" then top_y=top_y+scale
  181.   elseif k=="S" then top_y=top_y-scale
  182.   elseif k=="A" then left_x=left_x+scale
  183.   elseif k=="D" then left_x=left_x-scale
  184.   elseif k=="VK_RETURN" then
  185.     if #patterns == 0 then return end
  186.     function canvas:onHover() end
  187.     function canvas:onContext() end
  188.     function canvas:onMouseDown() end
  189.     function canvas:onMouseUp() end
  190.     draw_color = 0xff9900ff
  191.     hash = points_to_hash()
  192.     decode(directory,hash)
  193.   end
  194. end
  195. function win:onClose()
  196.   if hash == nil then return end
  197.   if not (sys.File(directory).exists or sys.Directory(directory).exists) then
  198.     ui.warn("The file or folder no longer exists. Nothing will be reencoded.")
  199.     return
  200.   end
  201.   encode(directory,hash)
  202. end
  203. win:show()
  204. ui.task:wait()
Advertisement
Add Comment
Please, Sign In to add comment