Giter Club home page Giter Club logo

Comments (4)

MHumm avatar MHumm commented on June 30, 2024

Sorry for only finding time to follow up on this now.
Do you have any sample code demoing this? That would really help investigating and fixing this.

from delphiencryptioncompendium.

MHumm avatar MHumm commented on June 30, 2024

I did a test now (will publish the code used later). 10.000 iterations each for 2DES encrypting/decrypting the same string and comparing the result. Works flawlessly for 2DES and 3DES but seems to have a general failure for Shark, as there it produced 10.000 failures as the decrypted string never matched the plain text fed into the encryption method.

Mode used was CFB each time and cipher key etc. were all the same each time.
For me this suggests, that 2DES and 3DES do work but Shark has a general problem, despite having a unit test for it with data derived from the old 5.2/5.3 test program which does not report any error.

from delphiencryptioncompendium.

MHumm avatar MHumm commented on June 30, 2024

As promised here the code of the test application used. Does anybody spot any flaws in my test?

program Shark_3DES_2DES_Bugtest;

{$APPTYPE CONSOLE}

{$R *.res}

uses
System.SysUtils,
DECCipherModes in '..\Source\DECCipherModes.pas',
DECCiphers in '..\Source\DECCiphers.pas',
DECBaseClass in '..\Source\DECBaseClass.pas',
DECCipherBase in '..\Source\DECCipherBase.pas',
DECCipherFormats in '..\Source\DECCipherFormats.pas',
DECCRC in '..\Source\DECCRC.pas',
DECFormat in '..\Source\DECFormat.pas',
DECFormatBase in '..\Source\DECFormatBase.pas',
DECUtil in '..\Source\DECUtil.pas',
DECTypes in '..\Source\DECTypes.pas',
DECUtilRawByteStringHelper in '..\Source\DECUtilRawByteStringHelper.pas',
DECData in '..\Source\DECData.pas',
DECCipherInterface in '..\Source\DECCipherInterface.pas';

var
Cipher : TCipher_Shark;
// We use raw byte string here since Unicode handling of Windows console
// is not given
SourceText : RawByteString;
CipherText : string;
// Key for the initialization of our encryption run
CipherKey : RawByteString;
IV : RawByteString;
Input,
Output : TBytes;
i, n, ErrC : Integer;

const
cPlainText = 'Beispielklartext';
begin
Cipher := TCipher_Shark.Create;
// number of decryption failures
ErrC := 0;

try
try
for n := 1 to 10000 do
begin
// Init our encryption
CipherKey := 'Passwort';
IV := #0#0#0#0#0#0#0#0;
Cipher.Init(CipherKey, IV, 0);
Cipher.Mode := cmCBCx;

    SourceText := cPlainText; //'Beispielklartext';
    WriteLn(n:5, ' Source text: ' + SourceText);

    Input := System.SysUtils.BytesOf(SourceText);

    Write(n:5, ' Source text in hex:    ');
    for i := 0 to high(Input) do
      Write(IntToHex(Input[i], 2), ' ');
    WriteLn;

    // Encrypt
    Output := Cipher.EncodeBytes(Input);

    Write(n:5, ' Encrypted data in hex: ');
    for i := 0 to high(Output) do
      Write(IntToHex(Output[i], 2), ' ');

    WriteLn;

    // Decrypt
    Cipher.Init(CipherKey, IV, 0);
    Output := Cipher.DecodeBytes(Output);

    SourceText := System.SysUtils.StringOf(Output);

    WriteLn(n:5, ' Decrypted data: ' + SourceText);

    if SourceText <> cPlainText then
    begin
      inc(ErrC);
      WriteLn('Decryption error!');
    end;

    // Show that using a different key results in a different output
    WriteLn;

    CipherKey := 'Password';
    Cipher.Init(CipherKey, IV, 0);
    Output := Cipher.DecodeBytes(Output);

    SourceText := System.SysUtils.StringOf(Output);

    WriteLn('Decrypted with different key: ' + SourceText);
  end;

  WriteLn;
  WriteLn('Number of decription errors ', ErrC);
  ReadLn;
except
  on E: Exception do
    Writeln(E.ClassName, ': ', E.Message);
end;

finally
Cipher.Free;
end;
end.

from delphiencryptioncompendium.

MHumm avatar MHumm commented on June 30, 2024

Did another test with Shark cipher now. When changing the cipher key from 'Passwort' to 'TCipher_Shark', which is longer, it properly encrypts and decrypts the encrypted text. This has been run 10.000 times in a loop as well so I cannot find any failure. At least not with the simplistic description of @piker00. So I close this one now.

from delphiencryptioncompendium.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.