user1960364
user1960364

Reputation: 2001

Lua / PHP Encryption/Decryption

I'm new to the whole encryption/decryption playground. However, I'm trying to find a way to encrypt a string to send it over http. It doesn't have to be real secure, just something to discourage your common script-kiddy. It's not very important or sensitive data.

That being said, what would be the easiest way to implement an encryption/decryption algorithm that will easily work in Lua and PHP? PHP is so popular, I'm sure I could find a small class for just about any algorithm that isn't already in the mcrypt library... Therefore, I suppose this question is actually more-so targeted towards the easiest thing to implement in Lua.

Any suggestions? Examples? Thanks

Upvotes: 2

Views: 1912

Answers (1)

lhf
lhf

Reputation: 72312

If you can send binary data, try this:

function change(s,a)
    local t=""
    for i=1,#s do
        t=t..string.char((a*s:byte(i))%256)
    end
    return t
end

function encrypt(s)
    return change(s,3)
end

function decrypt(s)
    return change(s,171)
end

(Caveats: Not cryptographically secure. If the string you want to send is very long, change may be slow.)

Upvotes: 2

Related Questions