devomaa

Untitled

Jul 1st, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. local function get(what,where,name)
  2. print("Downloading " .. name)
  3. local handle = fs.open(where,"w")
  4. local otherHandle = http.get(what)
  5. handle.write(otherHandle.readAll())
  6. handle.close()
  7. otherHandle.close()
  8. end
  9. if not http then
  10. error("Please enable HTTP in CC config.")
  11. end
  12. if not http.websocket then
  13. error("Please enable WebSockets (either by downloading CC:Tweaked and installing it, or enabling it in CC:Tweaked config.")
  14. end
  15. if not fs.exists("sha256.lua") then
  16. get("https://pastebin.com/raw/qmHNTqad","sha256.lua","SHA256 API")
  17. end
  18. if not fs.exists("json.lua") then
  19. get("https://raw.githubusercontent.com/rxi/json.lua/master/json.lua","json.lua","JSON API")
  20. end
  21. if not fs.exists("soqet.lua") then
  22. get("https://raw.githubusercontent.com/Ale32bit/Soqet/master/soqet.lua","soqet.lua","Soqet")
  23. end
  24. if not fs.exists("string.random.lua") then
  25. get("https://gist.githubusercontent.com/haggen/2fd643ea9a261fea2094/raw/e9f2ada3154a3d207231d7426e4a00835c298a64/string.random.lua", "string.random.lua","string.random")
  26. end
  27. if not fs.exists("aes.lua") then
  28. get("https://gist.githubusercontent.com/devomaa/ca179f070adb8ce44f4982a3a3464de4/raw/80987437d1d128c04446d91b65b2060e5ebe7db2/aeslua.min.lua", "aes.lua", "AES API")
  29. end
  30. local function getHexRepresentationOfColor (color)
  31. return string.format ("%X",
  32. math.floor (math.log (color) / math.log (2)))
  33. end
  34. local function getDecimalRepresentationOfColor (hexRepresentation)
  35. return math.pow (2, tonumber (hexRepresentation, 16))
  36. end
  37. local sha = require("sha256")
  38. local json = require("json")
  39. local soqet = require("soqet")
  40. os.loadAPI("string.random.lua")
  41. local aes = require("aes")
  42. local function chat(username, password)
  43. print("Loading Chat...")
  44. soqet.open("soqetChat")
  45. math.randomSeed(sha(username .. "|/LAZYSALT-PJALS-1-4-1-2-SOQET-CHAT\|" .. password))
  46. local userID = string.random(32)
  47. soqet.auth(userID)
  48. soqet.send("soqetChat", "BACKLOG", {["credintals"] = {["userID"] = userID}})
  49. while true do
  50. parallel.waitForAny(function() local channel, message, meta = os.pullEvent("soqet_message")
  51. if channel == "soqetChat" and meta.message and meta.user and message == "MESSAGE" and meta.sendToUserHashed == sha(username) then
  52. print(aes.decrypt(userID, meta.user) .. ": " .. aes.decrypt(userID, meta.message))
  53. end end, function() local input = aes.encrypt(userID, read()) soqet.send("soqetChat", "DISTRIBUTE-MESSAGE", {["message"] = message, ["user"] = aes.encrypt(userID, username)}) end)
  54. end
  55. end
  56. if not fs.exists("soqetCredintals.json") then
  57. print("Enter your new Soqet-Chat username!")
  58. local username = read()
  59. print("Enter your new Soqet-Chat password!")
  60. local password = sha(read("*"))
  61. local credintals = {["username"] = username, ["password"] = password}
  62. local result = json.encode(credintals)
  63. soqet.open("soqetChat")
  64. soqet.send("soqetChat", "REGISTER", {["data"] = result})
  65. local file = fs.open("soqetCredintals.json","w")
  66. file.write(result)
  67. file.close()
  68. else
  69. local file = fs.open("soqetCredintals.json","r")
  70. local contents = file.readAll()
  71. local credintals = json.decode(contents)
  72. file.close()
  73. print("Logging in as " .. credintals.username)
  74. while true do
  75. print("Please enter your password")
  76. local password = sha(read("*"))
  77. if credintals.password == password then
  78. chat(credintals.username, credintals.password)
  79. break
  80. else
  81. print("Wrong Password!")
  82. end
  83. end
  84. end
Add Comment
Please, Sign In to add comment