Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- i am make alphabet shifter yes? for encoded messages.
- -- Ill try to add captilization as well..
- 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!]]
- local shift = -13
- local time1 = os.clock()
- function letter_value(x)
- local alphabet = "abcdefghijklmnopqrstuvwxyz"
- local d = x:lower()
- local value = 0
- for i=1,#alphabet do
- if d == string.sub(alphabet,i,i) then
- value = i
- break
- end
- end
- if value ~= 0 then
- return value
- else
- return x
- end
- end
- function value_letter(x)
- local alphabet = "abcdefghijklmnopqrstuvwxyz"
- local value = string.sub(alphabet,x,x)
- return value
- end
- -- if shift is greater than 26 or lower than -26 then
- if shift > 26 then
- shift = shift%26
- else
- shift = (shift%26)*-1
- end
- local g = ""
- for i=1,#input do
- local x = letter_value(string.sub(input,i,i))
- if x ~= string.sub(input,i,i) then
- local d
- x = x + shift
- if x > 26 then
- x = x - 26
- elseif x < 1 then
- x = x + 26
- end
- if string.sub(input,i,i) == string.sub(input,i,i):upper() then
- d = value_letter(x):upper()
- else
- d = value_letter(x)
- end
- g = g..d
- else
- g = g..string.sub(input,i,i)
- end
- end
- print(g.."\n\nTime taken: "..string.format("elapsed time: %.2f\n", os.clock() - time1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement