Norskel

[API] ChiffreVigenere

Nov 22nd, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. --cle = "chiffrement"
  2. --a = "BaseOs est 100% secure!"
  3. --at = {a:byte(1,#a)}
  4. --clet = {cle:byte(1,#cle)}
  5.  
  6. function chiffre(cle,text)
  7.   local retour = ""
  8.   local retourT = {}
  9.   local textT = {text:byte(1,#text)}
  10.   local cleT = {cle:byte(1,#cle)}
  11.   local ic = 1
  12.  
  13.   for i=1,#textT do  
  14.     if ic > #cleT-1 then
  15.       ic = 1
  16.     else
  17.       ic = ic+1
  18.     end
  19.    
  20.     retourT[i] = textT[i] + cleT[ic]  
  21.     --print(textT[i].."+"..cleT[ic].."="..retourT[i])
  22.     if retourT[i] > 255 then
  23.    
  24.       retourT[i] = retourT[i] - 255
  25.     end
  26.     --print(i.." "..ic)
  27.     retour = retour..string.char(retourT[i])    
  28.   end
  29.  
  30.   return retour  
  31.  
  32. end
  33.  
  34. function dechiffre(cle,text)
  35.   local retour = ""
  36.   local retourT = {}
  37.   local textT = {text:byte(1,#text)}
  38.   local cleT = {cle:byte(1,#cle)}
  39.   local ic = 1
  40.  
  41.   for i=1,#textT do  
  42.     if ic > #cleT-1 then
  43.       ic = 1
  44.     else
  45.       ic = ic+1
  46.     end
  47.    
  48.     retourT[i] = textT[i] - cleT[ic]  
  49.    --print(textT[i].."+"..cleT[ic].."="..retourT[i])
  50.     if retourT[i] < 0 then
  51.    
  52.       retourT[i] = retourT[i] + 255
  53.     end
  54.     --print(i.." "..ic)
  55.     retour = retour..string.char(retourT[i])    
  56.   end
  57.  
  58.   return retour  
  59.  
  60. end
Add Comment
Please, Sign In to add comment