无法解密加密数据lua

时间:2014-05-24 00:35:49

标签: encryption lua

你好我们atm我被困在我的脚本中我试图加密一些数据并在我想要但不能

时将其删除

我用

local function convert( chars, dist, inv )
   return string.char( ( string.byte( chars ) - 32 + ( inv and -dist or dist ) ) % 95 + 32 )
end

local function crypt(str,k,inv)
   local enc= "";
   for i=1,#str do
      if(#str-k[5] >= i or not inv)then
         for inc=0,3 do
            if(i%4 == inc)then
               enc = enc .. convert(string.sub(str,i,i),k[inc+1],inv);
               break;
            end
         end
      end
   end
   if(not inv)then
      for i=1,k[5] do
         enc = enc .. string.char(math.random(32,126));
      end
   end
   return enc;
end

local enc1 = {29, 58, 93, 28 ,27};
local str = "Hello World !";
local crypted = crypt(str,enc1)
print("Encryption: " .. crypted);
print("Decryption: " .. crypt(crypted,enc1,true));

所以打印

Encryption: #c)*J}s-Mj!=[f3`7AfW{XCW*.EI!c0,i4Y:3Z~{ 
Decryption: Hello World ! 

现在我想要做的只是解密我的加密字符串,有一个程序从服务器调用数据,所以我希望它加密,并在它到达我的程序后尝试删除它

local enc1 = {29, 58, 93, 28 ,27};
local str = "#c)*J}s-Mj!=[f3`7AfW{XCW*.EI!c0,i4Y:3Z~{";
local crypted = crypt(str,enc1)

print("Decryption: " .. crypt(crypted,enc1,true));

哪个应该基本上解密我加密的那个字符串但是不做它只是再次打开相同的字符串任何帮助?

1 个答案:

答案 0 :(得分:3)

在第二个代码段中,您在已加密的字符串crypt上调用了str。因此,根据您的需要,要么不加密两次:

local enc1 = {29, 58, 93, 28 ,27};
local str = "#c)*J}s-Mj!=[f3`7AfW{XCW*.EI!c0,i4Y:3Z~{";
print("Decryption: " .. crypt(crypted,enc1,true));

或解密两次:

local enc1 = {29, 58, 93, 28 ,27};
local str = "#c)*J}s-Mj!=[f3`7AfW{XCW*.EI!c0,i4Y:3Z~{";
local crypted = crypt(str,enc1)
print("Decryption: " .. crypt(crypt(crypted,enc1,true), enc1, true))