Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. --[[
  2. Checkusm calcluation. Enter the command into the command string below, but do no inlcude the start byte, checksum, or end byte. The result will be printed below.
  3. --]]
  4.  
  5. command = "\x01\x76\x1a\x01"
  6.  
  7.  
  8.  
  9.  
  10. local start, checksum, finish, output, readable = "\xfe", 0, "\xff", "", ""
  11. for c in command:gmatch(".") do
  12.   checksum = checksum + string.byte(c)
  13.   output = output .. c
  14. end
  15.  
  16. checksum = checksum % 255
  17.  
  18. output = output .. string.char(checksum)
  19. output = output:gsub("\x80", "\x80\x00")
  20. output = output:gsub("\xfe", "\x80\x7e")
  21. output = output:gsub("\xff", "\x80\x7f")
  22. output = start .. output .. finish
  23.  
  24. for c in output:gmatch(".") do
  25.   readable = readable .. string.format("\\x%02x", string.byte(c))
  26. end
  27.  
  28. print(string.format("Checksum: %02x\r\nString for command button: \"%s\"", string.byte(checksum), readable))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement