This is a very simple Encryption and provides very little protection. It can be reversed very easily. But its better than raw data.
-Darkmod
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | local function convert( chars, dist, inv ) return string.char( ( string.byte( chars ) - 32 + ( inv and -dist or dist ) ) % 95 + 32 ) end local function crypt(str,k,inv) local enc= ""; for i=1,#str do if(#str-k[5] >= i or not inv)then for inc=0,3 do if(i%4 == inc)then enc = enc .. convert(string.sub(str,i,i),k[inc+1],inv); break; end end end end if(not inv)then for i=1,k[5] do enc = enc .. string.char(math.random(32,126)); end end return enc; end local enc1 = {29, 58, 93, 28, 27}; local str = "This is an encrypted string."; local crypted = crypt(str,enc1) print("Encryption: " .. crypted); print("Decryption: " .. crypt(crypted,enc1,true)); -- returns: -- Encryption: /f&1Zg0=<l<#Ia/7Kr""Zq10Dl$KT)8b>%*JbV>Z^Ik!p=B@'7cHMY< -- Decryption: This is an encrypted string. |
have not tested it completely, but you will have to be careful that you do not end up with characters that break the strings.
for example
1 2 3 | local myEncodedString = "/f&1Zg0=<l<#Ia/7Kr""Zq10Dl$KT)8b>%*JbV>Z^Ik!p=B@'7cHMY<" print(decode(myEncodedString)) |
Have you taken a look at Corona's crypto support?
Yes crypto is a one way hashing encryption that can't be Decrypted locally.
what are you planning on encrypting with this? What is its purpose?
views:1799 update:2011/11/2 21:34:51