Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input = "According to all known laws of aviation; there is no way a bee should be able to fly. Its wings are too small to get its fat little body off the ground. The bee: of course, flies anyway because bees don't care what humans think is impossible."
- math.randomseed(os.time())
- key = {
- a = "%",
- b = "2",
- c = "+",
- d = "]",
- e = "@",
- f = "9",
- g = "~",
- h = "^",
- i = "`",
- j = ";",
- k = "*",
- l = "#",
- m = ")",
- n = "[",
- o = ":",
- p = "&",
- q = "i",
- r = "(",
- s = "/",
- t = "}",
- u = "7",
- v = "{",
- w = "1",
- x = "=",
- y = "_",
- z = "4",
- noise = "-",
- upper = "p",
- }
- key[" "] = "8"
- key["."] = "5"
- key[","] = "3"
- key[":"] = "o"
- key[";"] = "w"
- key["'"] = "\""
- key["!"] = "0"
- key["?"] = "!"
- function code(str)
- local r = ""
- for i = 1, #str do
- replaced = false
- char = string.sub(str, i, i)
- if math.random(1,5) == 1 then
- r = (r .. key.noise)
- end
- for _, v in pairs(key) do
- if string.lower(char) ~= char and string.lower(char) == _ then
- r = (r .. key.upper .. v)
- replaced = true
- elseif
- string.lower(char) == _ then
- r = (r .. v)
- replaced = true
- end
- if char == key.noise then
- replaced = true
- end
- end
- if (not replaced) then
- print("Invalid character: " .. char)
- end
- end
- return r
- end
- function decode(str)
- local r = ""
- for i = 1, string.len(str) do
- char = string.sub(str, i, i)
- if char ~= key.noise then
- for _, v in pairs(key) do
- if char == v then
- if v == key.upper then
- upper = true
- else
- if upper then
- r = r .. string.upper(_)
- else
- r = r .. _
- end
- upper = false
- end
- end
- end
- end
- end
- return r
- end
- a = code(input)
- print("Coded: " .. a)
- io.write("\n")
- a = decode(a)
- print("Decoded: " .. a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement