Advertisement
Guest User

encrypt

a guest
Aug 30th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. function encrypt(msg,key)
  2.   local num = ""
  3.   for i = 1, #key do
  4.     local let = key:sub(i,i):byte()
  5.     num = let <= 9  and num.."99"..let or let<=99 and num.."9"..let or num..let
  6.     num = #msg..num
  7.   end
  8.   math.randomseed(tonumber(num))
  9.   local encrypt = ""
  10.   for i = 1, #msg do
  11.     local rotation = math.random(0,94)
  12.     local byte = msg:sub(i,i):byte()
  13.     local rotate = rotation+byte <= 127 and rotation +byte or ((rotation+byte)%127)+32
  14.     encrypt = encrypt..string.char(rotate)
  15.   end
  16.   return encrypt
  17. end
  18.  
  19. function decrypt(msg,key)
  20.   local num = ""
  21.   for i = 1, #key do
  22.     local let = key:sub(i,i):byte()
  23.     num = let <= 9 and num.."99"..let or let<=99 and num.."9"..let or num..let
  24.     num = #msg..num
  25.   end
  26.   math.randomseed(tonumber(num))
  27.   local decrypt = ""
  28.   for i = 1, #msg do
  29.     local rotation = math.random(0,94)
  30.     local byte = msg:sub(i,i):byte()
  31.     local rotate = byte-rotation >= 32 and byte-rotation or byte-rotation
  32.     if rotate < 32 then
  33.       rotate = rotate+95
  34.     end
  35.     decrypt = decrypt..string.char(rotate)
  36.   end
  37.   return decrypt
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement