196 posts
Location
Norway
Posted 07 January 2013 - 01:22 AM
Here is a hashing function that allows for storing passwords secure on CC computers. As far as I know there is no way to decrypt the passwordEDIT: Code updated
local function encrypt(Str)
local OriginalString = tostring(Str)
local cry = {}
local randomSeed = 0
local cryptedOut = ""
local lenght = string.len(OriginalString)
local randomNumberAmmount = 255 --Dosn't need to be = lenght+10
local numberS = {}
for i=1, lenght do
numberS[i] = string.byte(OriginalString,i)
randomSeed = randomSeed + string.byte(OriginalString,i)
end
math.randomseed(randomSeed)
for i=1, lenght do
cryptedOut = cryptedOut .. math.random(randomNumberAmmount*(lenght+1)*(numberS[i]+1))
end
return cryptedOut
end
1054 posts
Posted 07 January 2013 - 01:35 AM
Aren't you hiding/overriding the string api? Does that even run?
196 posts
Location
Norway
Posted 07 January 2013 - 01:35 AM
Yeah it runs. Wut string api?
string.byte is standard in lua library
Edit:
It is just a function that can be accessed via os.loadAPI or just coded into a program
1054 posts
Posted 07 January 2013 - 01:38 AM
I'm thinking that by naming the function argument 'string', the string variable no longer holds the table/api. So you'd be indexing a string. I can't test it to be 100% sure, I'm on the phone.
196 posts
Location
Norway
Posted 07 January 2013 - 01:40 AM
oh, didn't think of that, but I have tested it with (string). Changed now tought
7508 posts
Location
Australia
Posted 07 January 2013 - 01:45 AM
yeh the code works…
Orwell I think string api should be fine. the whole scope. since string is an argument it would be local, and it should try to call the function on it first, once that doesn't work it would check global.
196 posts
Location
Norway
Posted 07 January 2013 - 01:54 AM
Here is small change to the program making it more secure(there was an error):
local function encrypt(Str)
local OriginalString = Str
local cry = {}
local randomSeed = 0
local cryptedOut = ""
local lenght = string.len(OriginalString)
local randomNumberAmmount = 255 --Dosn't need to be = 255
for i=1, lenght do
randomSeed = randomSeed + string.byte(OriginalString,i)
end
math.randomseed(randomSeed)
for i=1, lenght do
cryptedOut = cryptedOut .. math.random(randomNumberAmmount)*lenght
end
return cryptedOut
end
7508 posts
Location
Australia
Posted 07 January 2013 - 02:11 AM
Importand change (if not used the password will only encrypt the first letter):
I was just about to tell you about this bug :)/>
1054 posts
Posted 07 January 2013 - 02:13 AM
yeh the code works…
Orwell I think string api should be fine. the whole scope. since string is an argument it would be local, and it should try to call the function on it first, once that doesn't work it would check global.
That seems to be the case, it doesn't seem very logic to me and in most languages this would be the case only when string was undefined.
196 posts
Location
Norway
Posted 07 January 2013 - 02:16 AM
I was just about to tell you about this bug :)/>
:)/>
7508 posts
Location
Australia
Posted 07 January 2013 - 02:23 AM
That seems to be the case, it doesn't seem very logic to me and in most languages this would be the case only when string was undefined.
most languages aren't like Lua though and allow functions or any variable to be assigned to a variable. however they do, do similar things with scope.
1054 posts
Posted 07 January 2013 - 02:34 AM
That seems to be the case, it doesn't seem very logic to me and in most languages this would be the case only when string was undefined.
most languages aren't like Lua though and allow functions or any variable to be assigned to a variable. however they do, do similar things with scope.
In practically every language I know (and I'm 100% sure about the lower level ones like C++ and Java), the variable is either defined or not and the inner scope has priority. So it's not really similar, it's much strict and straight forward. So it would be either be a string or a table (a string in this case because of the local scope). But in this case the rvalue is a string, but when indexed it's a table. Quite confusing :P/>
87 posts
Location
Basement
Posted 07 January 2013 - 03:16 AM
So this is a hashing algorithm not encryption then if it is 'irreversible'? Also test it works, look good :)/>
196 posts
Location
Norway
Posted 16 April 2013 - 03:08 AM
Code updated and is now more secure.