Posted 30 August 2015 - 05:57 AM
I got bored a few days ago, so I wrote up a simple little form of hashing and encryption. I really have no idea how secure these actually are, so I am releasing them so others can help my figure it out. :D/>
Tired of those huge hashing apis, well here is a 19 line one!
Example of using hash function. Notice, when using it to only put in 2 arguments.
pastebin for hashing: http://pastebin.com/J7iXAAek
Made a short little encryption api to go with the hashing api. It is built upon the same concept. Just know the encryption is only as strong as the key you use to encrypt.
Encryption code
pastebin for encryption: http://pastebin.com/cyiVcsMm
Note: It is still possible to brute force this just as it would be for any other hashing/encryption api.
Note2: I believe this is secure, but if anyone can show me it is not I would love to know. I am basing another project of mine off of a similar concept, and would like to know that it isn't secure before I finish.
Tired of those huge hashing apis, well here is a 19 line one!
Example of using hash function. Notice, when using it to only put in 2 arguments.
Spoiler
function hash(msg,salt,bool)
if not bool then
for i = 1, 10 do
msg = hash(msg,salt or "",true)
end
end
local num = ""
local salt = salt ~= nil and salt..msg or msg
for i = 1, #salt do
local let = salt:sub(i,i):byte()
num = let <= 9 and num.."99"..let or let<=99 and num.."9"..let or num..let
end
math.randomseed(tonumber(num))
local hashed = ""
for i = 1, 250 do
hashed = hashed..string.char(math.random(32,127))
end
return hashed
end
print(hash("hi","salt"))
pastebin for hashing: http://pastebin.com/J7iXAAek
Made a short little encryption api to go with the hashing api. It is built upon the same concept. Just know the encryption is only as strong as the key you use to encrypt.
Encryption code
Spoiler
function encrypt(msg,key)
local num = ""
for i = 1, #key do
local let = key:sub(i,i):byte()
num = let <= 9 and num.."99"..let or let<=99 and num.."9"..let or num..let
num = #msg..num
end
math.randomseed(tonumber(num))
local encrypt = ""
for i = 1, #msg do
local rotation = math.random(0,94)
local byte = msg:sub(i,i):byte()
local rotate = rotation+byte <= 127 and rotation +byte or ((rotation+byte)%127)+32
encrypt = encrypt..string.char(rotate)
end
return encrypt
end
function decrypt(msg,key)
local num = ""
for i = 1, #key do
local let = key:sub(i,i):byte()
num = let <= 9 and num.."99"..let or let<=99 and num.."9"..let or num..let
num = #msg..num
end
math.randomseed(tonumber(num))
local decrypt = ""
for i = 1, #msg do
local rotation = math.random(0,94)
local byte = msg:sub(i,i):byte()
local rotate = byte-rotation >= 32 and byte-rotation or byte-rotation
if rotate < 32 then
rotate = rotate+95
end
decrypt = decrypt..string.char(rotate)
end
return decrypt
end
pastebin for encryption: http://pastebin.com/cyiVcsMm
Note: It is still possible to brute force this just as it would be for any other hashing/encryption api.
Note2: I believe this is secure, but if anyone can show me it is not I would love to know. I am basing another project of mine off of a similar concept, and would like to know that it isn't secure before I finish.
Edited on 31 August 2015 - 01:40 AM