XaskeL

Untitled

Dec 21st, 2019
141
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local KEY = "sampletext"
  2.  
  3. addEventHandler("onResourceStart", resourceRoot, function()
  4. -- ENCODE
  5. local file = File.open("test.txt")
  6. local raw = file:read(file.size)
  7. file:close()
  8.  
  9. local len = #raw
  10. local lent = {}
  11.  
  12. -- file length to 256-digit notation
  13. local len0 = len
  14. while len0 > 0 do
  15. table.insert(lent, 1, len0 % 256)
  16. len0 = math.floor(len0 / 256)
  17. end
  18. table.insert(lent, #lent) -- #lent < 255
  19.  
  20. -- put \0 bytes. Expected length %4 == 0 , where length = file length + length of file length
  21. local deltafile = (4 - len % 4)
  22. local deltatable = #lent % 4
  23. local lendelta = (deltafile < deltatable) and (4 - deltatable + deltafile) or deltafile - deltatable
  24. for i = 1, lendelta do
  25. table.insert(lent, 1, 0)
  26. end
  27.  
  28. raw = raw .. string.char(unpack(lent))
  29.  
  30. local encoded = encodeString(
  31. "tea",
  32. raw,
  33. { key = KEY }
  34. )
  35.  
  36. local file = File.new("encoded")
  37. file:write(encoded)
  38. file:close()
  39.  
  40.  
  41. -- DECODE
  42. local decoded = decodeString(
  43. "tea",
  44. encoded,
  45. { key = KEY }
  46. )
  47.  
  48. local declen = #decoded
  49. local lentlen = decoded:sub(declen, declen):byte(1)
  50. local lent = 0
  51. for i = 1, lentlen do
  52. lent = lent + decoded:sub(declen - i, declen - i):byte(1) * 256 ^ (i - 1)
  53. end
  54.  
  55. local decodedcut = decoded:sub(1, lent)
  56.  
  57. local file = File.new("decoded.txt")
  58. file:write(decodedcut)
  59. file:close()
  60.  
  61. outputDebugString("Ready!")
  62. end)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×