Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function code(msg, key, mode, fileMode, convertNums)
- if convertNums then
- nm = ""
- for i = 1, math.floor(#msg/3), 1 do
- os.queueEvent("NCY")
- os.pullEvent("NCY")
- nm = nm .. string.char(tonumber(string.sub(msg,i*3-2,i*3)))
- end
- end
- key = tostring(key)
- msg = tostring(msg)
- if convertNums then msg = nm end
- local kn = 1
- local nmsg = ""
- for i = 1, #msg do
- if i % 50 == 0 then
- os.queueEvent("NO-CRASH-YIELD")
- os.pullEvent("NO-CRASH-YIELD")
- end
- curChar = string.sub(msg, i, i)
- nCurChar = string.byte(curChar)
- curKey = string.sub(key, kn, kn)
- nCurKey = string.byte(curKey)
- if mode == "encode" then
- newChar = nCurChar + nCurKey
- elseif mode == "decode" then
- newChar = nCurChar - nCurKey
- end
- if newChar >= 256 then
- newChar = newChar - 255
- end
- if newChar <= 0 then
- newChar = newChar + 255
- end
- if not fileMode then
- nmsg = nmsg .. string.char(newChar)
- else
- nc = tostring(newChar)
- while #nc < 3 do
- nc = "0"..nc
- end
- nmsg = nmsg .. nc
- end
- if kn == #key then
- kn = 1
- else
- kn = kn+1
- end
- end
- return nmsg
- end
- function encode(msg, key, doFile, convertNums)
- return code(msg, key, "encode", doFile, convertNums)
- end
- function decode(msg, key, doFile, convertNums)
- return code(msg, key, "decode", doFile, convertNums)
- end
Advertisement
Add Comment
Please, Sign In to add comment