Stolar228

ascii

Jan 25th, 2019
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. --local term = require("term")
  2. --local event = require("event")
  3.  
  4. local slovo
  5. local ler
  6. local s
  7. local ss
  8. local sl
  9. local buf
  10. local g
  11. local slovofinal
  12. local name
  13.  
  14. function savebuf()
  15. file = io.open("buf.txt", "w+")
  16. file:close()
  17. file = io.open("buf.txt", "a")
  18. file:write(buf)
  19. file:close()
  20. end
  21. function saveascii()
  22. file = io.open("ascii.txt", "a")
  23. file:write(g)
  24. file:close()
  25. end
  26. function openascii()
  27. file = io.open("ascii.txt", "r")
  28. buf = file:read()
  29. file:close()
  30. end
  31. function clearascii()
  32. file = io.open("ascii.txt", "w+")
  33. file:close()
  34. end
  35. while true do
  36. io.write(">")
  37. slovo = io.read()
  38. if slovo == "code" then
  39. io.write("code>")
  40. slovo = io.read()
  41. io.write("code=")
  42. clearascii()
  43. for i = 1,string.len(slovo) do
  44. g = string.byte(slovo,i).. "/"
  45. io.write(g)
  46. saveascii()
  47. end
  48. print()
  49. elseif slovo == "decode" then
  50. io.write("decode>")
  51. slovo = io.read()
  52. if slovo == "-bufer" then
  53. slovo = buf
  54. end
  55. s = 1
  56. io.write("decode=")
  57. while true do
  58. if (s + 1) > string.len(slovo) then break end
  59. ss = string.find(slovo,"/",s)
  60. sl = string.sub(slovo,s,ss-1)
  61. io.write(string.char(sl))
  62. -- print(sl)
  63. s = ss + 1
  64. end
  65. print()
  66. elseif slovo == "bufer" then
  67. openascii()
  68. print("bufer>".. buf)
  69. elseif slovo == "end" then
  70. break
  71. else print(" error")
  72. end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment