Advertisement
BobMe

Alphabet shifter, for encoded physical letters.

Nov 22nd, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. -- i am make alphabet shifter yes? for encoded messages.
  2. -- Ill try to add captilization as well..
  3.  
  4. local input = [[Pbzchgre fpvrapr vf n ernyyl, ernyyl pbby fhowrpg. Nf n pbqre, lbh yvggrenyyl unir gur cbjre gb perngr lbhe bja jbeyqf, fvzhyngr lbhe bja raivebzragf, naq unir sha qbvat vg nf jryy!]]
  5. local shift = -13
  6. local time1 = os.clock()
  7.  
  8. function letter_value(x)
  9. local alphabet = "abcdefghijklmnopqrstuvwxyz"
  10. local d = x:lower()
  11. local value = 0
  12. for i=1,#alphabet do
  13. if d == string.sub(alphabet,i,i) then
  14. value = i
  15. break
  16. end
  17. end
  18. if value ~= 0 then
  19. return value
  20. else
  21. return x
  22. end
  23. end
  24.  
  25. function value_letter(x)
  26. local alphabet = "abcdefghijklmnopqrstuvwxyz"
  27. local value = string.sub(alphabet,x,x)
  28. return value
  29. end
  30.  
  31. -- if shift is greater than 26 or lower than -26 then
  32. if shift > 26 then
  33. shift = shift%26
  34. else
  35. shift = (shift%26)*-1
  36. end
  37.  
  38. local g = ""
  39. for i=1,#input do
  40. local x = letter_value(string.sub(input,i,i))
  41. if x ~= string.sub(input,i,i) then
  42. local d
  43. x = x + shift
  44. if x > 26 then
  45. x = x - 26
  46. elseif x < 1 then
  47. x = x + 26
  48. end
  49. if string.sub(input,i,i) == string.sub(input,i,i):upper() then
  50. d = value_letter(x):upper()
  51. else
  52. d = value_letter(x)
  53. end
  54. g = g..d
  55. else
  56. g = g..string.sub(input,i,i)
  57. end
  58. end
  59.  
  60. print(g.."\n\nTime taken: "..string.format("elapsed time: %.2f\n", os.clock() - time1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement