Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- all your variables just in a table for ease
- local lookup = {
- a = 'D', b = 'E', c = 'F', d = 'G', e = 'H', f = 'I', g = 'J', h = 'K', i = 'L', j = 'M', k = 'N', l = 'O', m = 'P', n = 'Q', o = 'R', p = 'S', q = 'T', r = 'U', s = 'V', t = 'W', u = 'X', v = 'Y', w = 'Z', x = 'A', y = 'B', z = 'C', a = 'D', b = 'E', c = 'F', d = 'G', e = 'H', f = 'I', g = 'J', h = 'K', i = 'L', j = 'M', k = 'N', l = 'O', m = 'P', n = 'Q', o = 'R', p = 'S', q = 'T', r = 'U', s = 'V', t = 'W', u = 'X', v = 'Y', w = 'Z', x = 'A', y = 'B', z = 'C', A = 'd', B = 'e', C = 'f', D = 'g', E = 'h', F = 'i', G = 'j', H = 'k', I = 'l', J = 'm', K = 'n', L = 'o', M = 'p', N = 'q', O = 'r', P = 's', Q = 't', R = 'u', S = 'v', T = 'w', U = 'x', V = 'y', W = 'z', X = 'a', Y = 'b', Z = 'c'
- }
- -- encode is more accurate than encrypt
- function encode(str)
- -- create our return string
- local temp = ""
- -- loop through the input string
- for i = 1, #str do
- -- get the current character
- local char = str:sub(i,i)
- -- get the current char's mapped value in the table, if it's not in the table, i.e. a space, then just use itself
- local newChar = lookup[char] or char
- -- append the newChar to the return value
- temp = temp..newChar
- end
- -- return the new encoded string
- return temp
- end
- -- just some test code
- write('Text to be encoded: ')
- local input = read()
- local encoded = encode(input)
- print('Was: '..input..'\nNow: '..encoded)
Advertisement
Add Comment
Please, Sign In to add comment