--1337 7r4n51470r by mN4v

local file = nil
local leetfile = nil
local canEnter = false
local frase = ''
local mLinhas = {}

function checkExistence(file)
    local testf = io.open(file,'r')
    if testf then
        io.close(testf)
        return true
    else
        return false
    end
end

function makeLeet(letra, isEven)
    if letra == 't' then
        return '7'
    elseif letra == 'a' then
        return '4'
    elseif letra == 'e' then
        return '3'
    elseif letra == 'g' then
        return '6'
    elseif letra == 's' then
        return '5'
    elseif letra == 'z' then
        return '2'
    elseif letra == 'o' then
        return '0'
    elseif letra == 'l' then
        return '1'
    else
        if isEven%2 == 0 then
            return string.upper(letra)
        else
            return letra
        end
    end
end

function nextStep(file)
    if leetfile and leetfile ~= '.l33t' then
    for ecchiLine in io.lines(file) do
        local pos = 1
        frase = ''
        for letra in string.gmatch(ecchiLine, '%Z') do
            frase = frase .. makeLeet(string.lower(letra),pos)
            pos = pos + 1
        end
        if canEnter then
            frase = '\n' .. frase
        else
            canEnter = true
        end
        table.insert(mLinhas,frase)
    end
    local cText = ''
    for k,v in ipairs(mLinhas) do
        cText = cText .. v
    end
    local trnlArq = io.open(leetfile, 'w+')
    io.output(trnlArq)
    io.write(cText)
    io.close(trnlArq)
    print('success!')
    os.exit()
    else
        print('ERROR: missing file')
        os.exit()
    end
end

function getFile()
    if (os.getenv('APPDATA')) then
        os.execute('cls')
    else
        os.execute('clear')
    end
    io.write('Insert the file you want to translate (full path)\n>>')
    file = io.read()
    if (checkExistence(file)) then
         leetfile = file .. '.l33t'
         nextStep(file)
    else
         print('ERROR: missing file')
         os.exit()
    end
end

getFile()