Advertisement
InTesting

Key type concept

Jul 7th, 2021
1,288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.70 KB | None | 0 0
  1. --done in luau
  2. local msg = 'wow potato'
  3.  
  4. function GenerateRandomKey(len)local res=''for _=1,len do res..=tostring(math.random(1,10)-1)end return res end
  5.  
  6. function FACT_OffsetLetter(mult)
  7.     return function(msg,key)
  8.         local res=''
  9.        
  10.         for i=1,#msg do
  11.             local let = msg:sub(i,i)
  12.             local offset = key:sub(i,i)
  13.            
  14.             local NewByte =
  15.                 (let:byte() - 32 + offset * mult) % 223
  16.            
  17.             local newlet = string.char(NewByte + 32)
  18.             res ..= newlet
  19.         end
  20.        
  21.         return res
  22.     end
  23. end
  24.  
  25. local Encrypt = FACT_OffsetLetter(1)
  26. local Decrypt = FACT_OffsetLetter(-1)
  27.  
  28. local key = GenerateRandomKey(#msg)
  29. print(msg,key)
  30.  
  31. local m2 = Encrypt(msg,key)
  32.  
  33. print(m2)
  34.  
  35. local m3 = Decrypt(m2,key)
  36.  
  37. print(m3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement