Einzelnen Beitrag anzeigen

blackdrake

Registriert seit: 21. Aug 2003
Ort: Bammental
618 Beiträge
 
Delphi 10.3 Rio
 
#17

Re: Welche Verschlüsselung steckt hier hinter?

  Alt 28. Mai 2008, 22:02
Hallo.

Hier erstmal das Grundgerüst. Es funktioniert aber noch nicht wirklich... Format des Hashs ist unbekannt. Exceptions bei fehlerhafter Entschlüsselung werden nicht abgefangen und behandelt. Es existiert eine AccessViolation... Es ist nicht klar, ob ECB-Implementierung die selbe wie beim Originalcode des GTR2 ist...

Delphi-Quellcode:
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

  TGTR2SaveGameInfo = record
    Player: String;
    Time: String;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  DECHash, DECCipher, DECFmt;

function GTR2Decode(AInput: string): string;
var
  hash: THash_MD5;
  cipher: TCipher_3DES;
  tmp_md5, tmp_output: string;
const
  Secret = 'Gtr2Manager';
begin
  // DEC Initialisierung

  SetDefaultCipherClass(TCipher_3DES);
  SetDefaultHashClass(THash_MD5);

  // 1. Compute hash of key (Gtr2Manager)

  hash := THash_MD5.Create;
  try
    tmp_md5 := hash.CalcBinary(Secret, TFormat_Copy); // WELCHES FORMAT???
  finally
    hash.free;
  end;

  // 2. Use TripleDES ECB to decrypt data using computed key.

  cipher := TCipher_3DES.Create;
  try
    cipher.Mode := cmECBx;
    cipher.Init(tmp_md5);
    cipher.Decode(AInput, tmp_output, length(AInput)); // Dicke AccessViolation

    UniqueString(tmp_output); // Notwendig?
  finally
    cipher.free;
  end;

  result := tmp_output;
end;

function GTR2ReadSaveGame(AFilename: string): TGTR2SaveGameInfo;
var
  txt: TextFile;
  tmp_player, tmp_time: string;
begin
  AssignFile(txt, AFilename);
  Reset(txt);

  ReadLn(txt, tmp_player);
  result.Player := GTR2Decode(tmp_player);

  ReadLn(txt, tmp_time);
  result.Time := GTR2Decode(tmp_time);

  CloseFile(txt);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  sav: TGTR2SaveGameInfo;
begin
  sav := GTR2ReadSaveGame('C:\SaveGame.sav');
  showmessage('Player=' + sav.Player);
  showmessage('Time=' + sav.Time);
end;

end.
Daniel Marschall
  Mit Zitat antworten Zitat