【问题标题】:Failing to decrypt Encrypted Data lua无法解密加密数据lua
【发布时间】:2014-05-24 10:00:37
【问题描述】:

大家好,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));

这应该基本上解密我加密的那个字符串但不这样做它只是再次打印相同的字符串对此有任何帮助吗??

【问题讨论】:

  • 从您的第二个代码中删除加密步骤local crypted = crypt(str,enc1)
  • 我想你想改用crypt(str, enc1, true)

标签: encryption lua


【解决方案1】:

在您的第二个代码 sn-p 中,您在已加密的字符串 str 上调用了 crypt。所以根据你的需要,要么不要加密两次:

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))

【讨论】:

  • 工作完美,感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-03
  • 2020-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-16
相关资源
最近更新 更多