PrinceOfCookies

Untitled

Jul 22nd, 2024 (edited)
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. -- Vigenère cipher encryption
  2. function v(k,m)local e={}local l=#k for i=1,#m do local a=k:byte((i-1)%l+1)local b=m:byte(i)e[i]=string.char(bit32.bxor(b,a))end return table.concat(e)end
  3.  
  4. -- Base64 encoding
  5. local B='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  6. function b64e(d)local e={}local l=#d local i=1 while i<=l do local a=d:byte(i)or 0 local b=d:byte(i+1)or 0 local c=d:byte(i+2)or 0 local c=(a*65536)+(b*256)+c e[#e+1]=B:sub(math.floor(c/262144)+1,math.floor(c/262144)+1)e[#e+1]=B:sub(math.floor(c/4096)%64+1,math.floor(c/4096)%64+1)e[#e+1]=B:sub(math.floor(c/64)%64+1,math.floor(c/64)%64+1)e[#e+1]=B:sub(c%64+1,c%64+1)i=i+3 end local p=#d%3 if p==1 then e[#e-1]='=' e[#e]='=' elseif p==2 then e[#e]='=' end return table.concat(e)end
  7.  
  8. -- Base64 decoding
  9. function b64d(e)local d={}local i=1 local l=#e local function c2v(c)local idx=B:find(c) return idx and(idx-1)or 0 end while i<=l do local a=c2v(e:sub(i,i)) local b=c2v(e:sub(i+1,i+1)) local c=c2v(e:sub(i+2,i+2)) local d=c2v(e:sub(i+3,i+3)) local c=(a*262144)+(b*4096)+(c*64)+d d[#d+1]=string.char(math.floor(c/65536)%256) if b~=64 then d[#d+1]=string.char(math.floor(c/256)%256) end if d~=64 then d[#d+1]=string.char(c%256) end i=i+4 end return table.concat(d)end
  10.  
  11. -- Example usage
  12. local k="HTIWaoithwaioPTHio"local m="Hello World"local b64=b64e(m)print("Base64 Encoded:",b64)local e=v(k,b64)print("Vigenère Encrypted:",e)print("Base64 Decoded:",b64d(v(k,e)))
  13.  
Add Comment
Please, Sign In to add comment