LoliSmasher2001

gLua XOR cipher example

Nov 12th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.54 KB | None | 0 0
  1. --[[
  2.     basic XOR cipher for gLua
  3.     by Haffy
  4.    
  5.     The purpose of this is just to serve as an example for people wanting to encrypt data
  6.     using a basic method of encryption known as the XOR cipher (https://en.wikipedia.org/wiki/XOR_cipher)
  7. ]]
  8.  
  9. -- this is the key we're going XOR each character with
  10. local key = 0xA;
  11.  
  12. local function CipherString(str)
  13.     local new_str = "";
  14.     for i = 1, string.len(str) do
  15.         new_str = new_str .. string.char(bit.bxor(key, string.byte(str[i])));
  16.     end
  17.     return new_str;
  18. end
  19.  
  20. print(CipherString("hello world!));
Add Comment
Please, Sign In to add comment