Advertisement
LDDestroier

Test CC Hash function (LDD-1)

Feb 1st, 2016
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. --[[
  2. Unsure if this is super secure. It does work, however, no errors.
  3. Turns two strings (message, key) into a big ol' number. Made in, like, an hour.
  4.  
  5. Get with
  6.  pastebin get xn9Shvy6 ldd
  7.  std pb xn9Shvy6 ldd
  8.  An 'std ld' entry will be added IF this proves to be good.
  9. --]]
  10.  
  11. shuffle = function(str) --Rearranges the letters in a string, like shuffling a deck of cards bridge style.
  12.     local output = ""
  13.     local c = math.ceil
  14.     for a = 1, #str do
  15.         if a % 2 == 0 then
  16.             output = output..str:sub(-c(a/2),-c(a/2))
  17.         else
  18.             output = output..str:sub(c(a/2),c(a/2))
  19.         end
  20.     end
  21.     return output
  22. end
  23.  
  24. rollOver = function(num,max)
  25.     return math.floor(num % max), math.floor(num / max)
  26. end
  27.  
  28. letterize = function(num)
  29.     local output = ""
  30.     local strnum = tostring(num)
  31.     for a = 1, #strnum do
  32.         local newnum = string.sub(string.byte(strnum:sub(a,a)),1,3)
  33.         if #newnum < 3 then
  34.             newnum = string.rep("0",3-#newnum)..newnum
  35.         end
  36.         output = output..newnum
  37.     end
  38.     return output
  39. end
  40.  
  41. unletterize = function(str)
  42.     local output = ""
  43.     for a = 1, math.ceil(#str/3) do
  44.         output = output..string.char(tonumber(str:sub((a*3)-2,(a*3))))
  45.     end
  46.     return output
  47. end
  48.  
  49. hash = function(str,salt,_len) --Input string, string. Must have 2 arguments, or else you will DIE
  50.     local num_key, num_str, tab_key, tab_str, output = "", "", {}, {}, ""
  51.     local key = salt or shuffle(str)
  52.     local length = _len or 64
  53.     for a = 1, #key do
  54.         num_key = num_key..string.byte(key:sub(a,a))
  55.         table.insert(tab_key,string.byte(key:sub(a,a)))
  56.     end
  57.     for a = 1, #str do
  58.         num_str = num_str..string.byte(str:sub(a,a))
  59.         table.insert(tab_str,string.byte(str:sub(a,a)))
  60.     end
  61.     for a = 1, #tab_key do
  62.         for b = 1, #tab_str do
  63.             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)))
  64.         end
  65.     end
  66.     output = shuffle(letterize(string.gsub(shuffle(output),"%.","")))
  67.     local realout = ""
  68.     for a = 1, math.ceil(#output/3) do
  69.         local newchar = tostring(rollOver(tonumber(output:sub((a*3)-2,a*3)),256))
  70.         realout = realout..(string.rep("0",3-#newchar)..newchar)
  71.     end
  72.     output = unletterize(realout)
  73.     output = output:rep(math.ceil(length/#output)):sub(1,length)
  74.     return output
  75. end
  76.  
  77. --if you're going to put this in your program, you can omit all lines below
  78.  
  79. local tArg = {...}
  80. local str,salt,len = tArg[1], tArg[2], tArg[3]
  81. if shell and str then
  82.     local scr_x, scr_y = term.getSize()
  83.     local smeghead = hash(str,salt,len)
  84.     term.setBackgroundColor(colors.white)
  85.     term.setTextColor(colors.black)
  86.     write(smeghead)
  87.     local ex,ey = term.getCursorPos()
  88.     term.setBackgroundColor(colors.black)
  89.     term.setTextColor(colors.white)
  90.     write(string.rep(" ",(scr_x-ex)+1))
  91.     print("\nlength = "..#smeghead)
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement