Advertisement
ComputerMan123

AES Encryption by TheDacinator

Nov 22nd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. --Usable Characters 32-126
  2. encrypt = function(key,message)
  3. local counter = 1
  4. local out = ""
  5. if type(key) ~= "string" or string.len(key) < 1 then
  6. error("Invalid Key")
  7. end
  8. for i = 1,string.len(message) do
  9. local c = string.byte(string.sub(key,counter,counter))-32+string.byte(string.sub(message,i,i))
  10. if c > 126 then
  11. c = c - 94
  12. end
  13. counter = counter + 1
  14. if counter > string.len(key) then
  15. counter = 1
  16. end
  17. out = out..string.char(c)
  18. end
  19. return out
  20. end
  21. decrypt = function(key,message)
  22. if (not key) or type(key) ~= "string" or string.len(key) < 1 then
  23. error("Invalid Key")
  24. end
  25. local counter = 1
  26. local out = ""
  27. for i = 1,string.len(message) do
  28. local c = string.byte(string.sub(message,i,i))-(string.byte(string.sub(key,counter,counter))-32)
  29. if c < 32 then
  30. c = c + 94
  31. end
  32. counter = counter + 1
  33. if counter > string.len(key) then
  34. counter = 1
  35. end
  36. out = out..string.char(c)
  37. end
  38. return out
  39. end
  40. generateKey = function(length)
  41. if (not length) or type(length) ~= "number" or length < 1 then
  42. error("Invalid Length")
  43. end
  44. local out = ""
  45. for i = 1,length do
  46. out = out..string.char(math.random(32,126))
  47. end
  48. return out
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement