Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- charValues = {
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
- "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e",
- "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
- "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9",
- "0", " ", ".", ",", ")", "(", "*", "&", "%", "$", "#", "@", "!", "+", "=", ":",
- ";", "\"", "'", "?", "/", "~", "-"
- }
- function convToCV(s, b)
- local nS = ""
- for i=1,string.len(s) do
- o = string.sub(s, i, i)
- for i=1,#charValues do
- if o == charValues[i] then
- if b then
- nS = nS..i
- else
- nS = nS.."-"..i
- break
- end
- end
- if i > #charValues then
- error("Character not present")
- end
- end
- end
- return nS
- end
- function encrypt(s, k)
- if not k then return false end
- local k = tostring(k)
- local nS = ""
- local cS = convToCV(s)
- local kL = #k
- local kC = 1
- local c
- local nK
- local t = false
- local th = false
- local f = false
- local eK
- for i=1,#cS do
- c = string.sub(cS, i, i)
- if c ~= "-" and not t and not th and not f then
- if string.sub(cS, i+1, i+1) ~= "-" then
- c = string.sub(cS, i, i+1)
- t = true
- if string.sub(cS, i+2, i+2) ~= "-" then
- c = string.sub(cS, i, i+2)
- th = true
- if string.sub(cS, i+3, i+3) ~= "-" then
- c = string.sub(cS, i, i+3)
- f = true
- end
- end
- end
- nK = string.sub(k, kC, kC)
- kC = kC + 1
- if not tonumber(tostring(nK)) then
- nK = convToCV(nK, true)
- end
- if kC > kL then kC = 1 end
- eK = string.sub(k, 1, 1)
- c = tonumber(c) + tonumber(nK) + tonumber(convToCV(eK, true))
- nS = nS.."-"..c
- else
- if f then
- f = false
- elseif th then
- th = false
- elseif t then
- t = false
- end
- end
- end
- return nS
- end
- function decrypt(s, k)
- if not k then return false end
- local nS = ""
- local k = tostring(k)
- local c
- local t = false
- local th = false
- local f = false
- local kL = #k
- local kC = 1
- local nK
- local eK
- for i=1,#s do
- c = string.sub(s, i, i)
- if c ~= "-" and not t and not th and not f then
- if string.sub(s, i+1, i+1) ~= "-" then
- c = string.sub(s, i, i+1)
- t = true
- if string.sub(s, i+2, i+2) ~= "-" then
- c = string.sub(s, i, i+2)
- th = true
- if string.sub(s, i+3, i+3) ~= "-" then
- c = string.sub(s, i, i+3)
- f = true
- end
- end
- end
- nK = string.sub(k, kC, kC)
- kC = kC + 1
- if not tonumber(nK) then
- nK = convToCV(nK, true)
- end
- if kC > kL then kC = 1 end
- eK = string.sub(k, 1, 1)
- c = tonumber(c) - tonumber(nK) - tonumber(convToCV(eK, true))
- if c < 1 then
- c = 1
- elseif c > #charValues then
- c = #charValues - 1
- end
- c = charValues[c]
- nS = nS..c
- else
- if f then
- f = false
- elseif th then
- th = false
- elseif t then
- t = false
- end
- end
- end
- return nS
- end
Advertisement
Add Comment
Please, Sign In to add comment