Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Unsure if this is super secure. It does work, however, no errors.
- Turns two strings (message, key) into a big ol' number. Made in, like, an hour.
- Get with
- pastebin get xn9Shvy6 ldd
- std pb xn9Shvy6 ldd
- An 'std ld' entry will be added IF this proves to be good.
- --]]
- shuffle = function(str) --Rearranges the letters in a string, like shuffling a deck of cards bridge style.
- local output = ""
- local c = math.ceil
- for a = 1, #str do
- if a % 2 == 0 then
- output = output..str:sub(-c(a/2),-c(a/2))
- else
- output = output..str:sub(c(a/2),c(a/2))
- end
- end
- return output
- end
- rollOver = function(num,max)
- return math.floor(num % max), math.floor(num / max)
- end
- letterize = function(num)
- local output = ""
- local strnum = tostring(num)
- for a = 1, #strnum do
- local newnum = string.sub(string.byte(strnum:sub(a,a)),1,3)
- if #newnum < 3 then
- newnum = string.rep("0",3-#newnum)..newnum
- end
- output = output..newnum
- end
- return output
- end
- unletterize = function(str)
- local output = ""
- for a = 1, math.ceil(#str/3) do
- output = output..string.char(tonumber(str:sub((a*3)-2,(a*3))))
- end
- return output
- end
- hash = function(str,salt,_len) --Input string, string. Must have 2 arguments, or else you will DIE
- local num_key, num_str, tab_key, tab_str, output = "", "", {}, {}, ""
- local key = salt or shuffle(str)
- local length = _len or 64
- for a = 1, #key do
- num_key = num_key..string.byte(key:sub(a,a))
- table.insert(tab_key,string.byte(key:sub(a,a)))
- end
- for a = 1, #str do
- num_str = num_str..string.byte(str:sub(a,a))
- table.insert(tab_str,string.byte(str:sub(a,a)))
- end
- for a = 1, #tab_key do
- for b = 1, #tab_str do
- output = output..tostring(math.sqrt(tonumber(tab_key[a])+tonumber(tab_str[b]))+math.sqrt((#str-#tostring(tab_str[b]))^2+(#key-#tostring(tab_key[a]))^2)/(tonumber(tab_str[b]+#str)))
- end
- end
- output = shuffle(letterize(string.gsub(shuffle(output),"%.","")))
- local realout = ""
- for a = 1, math.ceil(#output/3) do
- local newchar = tostring(rollOver(tonumber(output:sub((a*3)-2,a*3)),256))
- realout = realout..(string.rep("0",3-#newchar)..newchar)
- end
- output = unletterize(realout)
- output = output:rep(math.ceil(length/#output)):sub(1,length)
- return output
- end
- --if you're going to put this in your program, you can omit all lines below
- local tArg = {...}
- local str,salt,len = tArg[1], tArg[2], tArg[3]
- if shell and str then
- local scr_x, scr_y = term.getSize()
- local smeghead = hash(str,salt,len)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- write(smeghead)
- local ex,ey = term.getCursorPos()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- write(string.rep(" ",(scr_x-ex)+1))
- print("\nlength = "..#smeghead)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement