简体   繁体   English

从加密方法解密

[英]Decryption from encryption method

I am needing to re-write a decryption method for an old piece of code, unfortunately the original decryption method has been lost on we only have access to the encryption. 我需要为旧代码重新编写一种解密方法,不幸的是,由于我们只能访问加密,因此原来的解密方法已经丢失。

type
  TintArray = array [0 .. 1] of Cardinal;
  TKeyArray = Array [0 .. 3] of Cardinal;

const
  KeyArray: TKeyArray = (858945348, 1144282739, 828794915, 556884274);

  procedure Encipher(var V, W: TintArray);
  var
    y, z, sum, delta, a, b, c, d, n: Cardinal;
    iCounter: Integer;
  begin
    y := V[0];
    z := V[1];
    sum := 0;
    delta := $9E3779B9; // 2654435769;//0x9E3779B9;
    a := KeyArray[0];
    b := KeyArray[1];
    c := KeyArray[2];
    d := KeyArray[3];
    n := 32;
    for iCounter := n downto 1 do begin
      sum := sum + delta;
      y := y + (((z shl 4) + a) xor (z + sum) xor ((z shr 5) + b));
      z := z + (((y shl 4) + c) xor (y + sum) xor ((y shr 5) + d));
    end;
    W[0] := y;
    W[1] := z;
  end;

I have tried mundane things like changing all the "+" to "-" however I did not have much hope as I really don't actually understand the code at all. 我已经尝试了一些平凡的事情,例如将所有的“ +”更改为“-”,但是我并不抱有太大希望,因为我实际上根本不了解代码。

This is the Tiny Encryption Algorithm (TEA). 这是微小的加密算法(TEA)。 Check it out on Wikipedia . Wikipedia上查看。

Your decryption routine should be something like this (keeping with your naming conventions, etc.): 您的解密例程应该是这样的(遵循您的命名约定等):

procedure Decipher(var V, W: TintArray);
var
  y, z, sum, delta, a, b, c, d, n: Cardinal;
  iCounter: Integer;
begin
  y := V[0];
  z := V[1];
  sum := $C6EF3720;
  delta := $9E3779B9; // 2654435769;//0x9E3779B9;
  a := KeyArray[0];
  b := KeyArray[1];
  c := KeyArray[2];
  d := KeyArray[3];
  n := 32;
  for iCounter := n downto 1 do begin
    z := z - (((y shl 4) + c) xor (y + sum) xor ((y shr 5) + d));
    y := y - (((z shl 4) + a) xor (z + sum) xor ((z shr 5) + b));
    sum := sum - delta;
  end;
  W[0] := y;
  W[1] := z;
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM