#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    1
    Rep Power
    0

    Code explanation


    Hi, i cannot understand the behavior of this code. (the bold code snippets)

    Can someone explain what it does exactly ?
    Code:
    const
     _SIZE       = $2000;
     _BLOCK_SIZE = $7C;
    
     TBlock = array [0 .. _BLOCK_SIZE -1] of Byte;
     PBlock = ^TBlock;
    
     TBlockRec = packed record
      ID: Word;
      Index: Word;
      Name: array [0 .. $63] of AnsiChar;
      Unk: array [0 .. $19] of Byte;
     end;
    
     PBlockRec = ^TBlockRec;
    
     TBlockArray = array [0 .. _SIZE -1] of TBlock;
     PBlockArray = ^TBlockArray;
    
     TBlockRecArray = array of TBlockRec;
    
    [I]procedure Decrypt3Bytes (var Buffer: TBlock);
    const
     Key : array [0 .. 2] of Byte = ($FC, $CF, $AB);
    var
     i: Integer;
    begin
     for i := 0 to _BLOCK_SIZE -1 do
      Buffer[i] := Buffer xor Key[i mod 3];
    end;
    Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,055
    Rep Power
    383
    Code:
    TBlockRec = packed record
    In a packed record fields are not padded for optimized access.
    Each field follows the prior field in the next memory byte.

    Code:
    Byte = ($FC, $CF, $AB)
    This is simply defining the contents of the constant Key which is defined as a three byte array.

    Code:
    Buffer[i] := Buffer[i] xor Key[i mod 3];
    Given the previous two explanations this should be clear.
    Look up xor and mod in the help file if you are not familiar with them. After that, post any follow up questions you may still have.

    Clive

IMN logo majestic logo threadwatch logo seochat tools logo