etelan

IdentificationCardGenerator.lua

Dec 12th, 2021 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. local math = require("math")
  2. local io = require("io")
  3. local os = require("os")
  4.  
  5. -- Initial file setup, with name input
  6. local file = io.open("generated.3d", "w")
  7. file:write("{")
  8.  
  9. -- Gather user input for name and word
  10. print("Please provide your name")
  11. local name = io.read()
  12.  
  13. print("Choose a random number for UID generation perposes")
  14. local numberChosen = io.read()
  15.  
  16. -- Can change this to something more secure in the future.
  17. local word = name
  18.  
  19. function seedGenerator (word)
  20. -- Calculating the seed
  21. local seed = 0
  22. for i = 1, #word do
  23. seed = seed + string.byte(word:sub(i,i))
  24. end
  25. return seed
  26. end
  27.  
  28. -- Encrypt the word into a unique identifier.
  29. math.randomseed(numberChosen)
  30. local encryptedWord = ""
  31. for i = 1, #word do
  32. encryptedWord = encryptedWord .. tostring( string.char ( string.byte(word:sub(i,i) ) + math.random(1,3) ) )
  33. end
  34.  
  35. -- Write out our initial identifiers
  36. file:write('\n label = "' .. name .. " - " .. encryptedWord .. '",')
  37. file:write('\n tooltip = "This key was generated by Etelan",')
  38. file:write('\n shapes = {')
  39. file:close()
  40.  
  41. -- Generates the shapes
  42. function generateStructure (word)
  43.  
  44. local file = io.open("generated.3d", "a")
  45.  
  46. -- Set the seed
  47. math.randomseed(seedGenerator(word))
  48.  
  49. -- x number of different blocks total.
  50. local n = 5
  51.  
  52. for i = 1,n do
  53.  
  54. -- Start writing the block
  55. file:write('\n {')
  56.  
  57. -- Generate Numbers
  58. local numbers = {}
  59.  
  60. for block = 1,6 do
  61. numbers[block] = math.random(1,11)
  62. if block>3 then
  63. while numbers[block] == numbers[block - 3] do
  64. numbers[block] = math.random(1,11)
  65. end
  66. end
  67. end
  68.  
  69. -- Write out the vectors created
  70. for i = 1,6 do
  71. file:write(tostring(numbers[i]) .. ",")
  72. end
  73.  
  74. -- Lua has no switch statement, therefore I long for death.
  75. -- This code choses the block, and then ends the block code.
  76. if i == 1 then file:write(' texture="chisel:blocks/antiblock/red"},') end
  77. if i == 2 then file:write(' texture="chisel:blocks/antiblock/blue"},') end
  78. if i == 3 then file:write(' texture="chisel:blocks/antiblock/white"},') end
  79. if i == 4 then file:write(' texture="chisel:blocks/antiblock/yellow"},') end
  80. if i == 5 then file:write(' texture="chisel:blocks/antiblock/orange"},') end
  81. if i == 6 then file:write(' texture="chisel:blocks/antiblock/lime"') end
  82.  
  83. end
  84.  
  85. -- Tidy up the end of the file
  86. file:write("\n }")
  87. file:write("\n}")
  88. file:close()
  89.  
  90. end
  91.  
  92. -- Call our method to generate the seed and also our shapes and encryption.
  93. generateStructure(word)
  94.  
  95. -- Generate the object!
  96. print("\n\n [Starting Print Job] \n\n")
  97. os.execute("print3d generated.3d")
  98. print("\n\nAll done, pickup your key.")
Add Comment
Please, Sign In to add comment