Advertisement
NekoLogi

encryption.lua

Oct 6th, 2022 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | Source Code | 0 0
  1. resources = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" , "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "`", "~", "<", ">", "?", "/", "\\", "|" }
  2.  
  3. function encrypt(message, bit)
  4.     local MSG = tostring(message)
  5.     local finalstring = ""
  6.     local count = 0
  7.     MSG:gsub(".", function(c)
  8.         for i,v in pairs(resources) do
  9.             count = count + 1
  10.             if v == c then
  11.                 finalstring = finalstring .. count * bit /69
  12.                 count = 0
  13.             end
  14.        end
  15.   end)
  16.   return finalstring
  17. end
  18.  
  19. function decrypt(message, bit)
  20.     local MSG = tostring(message)
  21.     local finalstring = ""
  22.     local count = 0
  23.     local resource_idx = 0
  24.     while MSG ~= "" do
  25.         count = count + 1
  26.         if count > 1000 then
  27.             return nil, "Can not decrypt"
  28.         end
  29.         resource_idx = resource_idx + 1
  30.         if resource_idx > #resources then
  31.             resource_idx = resource_idx - #resources
  32.             finalstring = finalstring .. " "
  33.         end
  34.         local code = "" .. count * bit /69
  35.         if MSG:sub(1, #code) == code then
  36.             MSG = MSG:sub(#code + 1)
  37.             finalstring = finalstring .. resources[resource_idx]
  38.             count = #resources - resource_idx
  39.             resource_idx = 0
  40.         end
  41.    end
  42.    return finalstring
  43. end
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement