in reply to DES in Perl

Caveat: I know next to nothing about the DES algorithm so am not going to comment on it here.

so I came to the conclusion that I am not reading the input file as 8 byte chunks correctly or as them

Ordinarily, that would mean you would just look at the readInputToArray() subroutine. However, the lack of strict and the profusion of global variables (such as $bytes and @FileArray) is going to make the debugging very difficult. Please do yourself a massive favour and limit the scope of your variables and make your subroutines as self-contained as possible. eg. have readInputToArray() return @FileArray so that the subroutine can be tested in isolation.

All that said, this line is concerning me:

my $padding = "0" x $diff;

Unfamiliar as I am with DES, this shows that you are padding the read string with "0"s - that is a string with each character being ASCII character "0" (dec 48 or hex 0x30) when what I can only guess you actually want is dec 0 or hex 0x00 which is the ASCII NUL. Is this a/the flaw? You tell me :-)

Replies are listed 'Best First'.
Re^2: DES in Perl
by TomY (Initiate) on Nov 14, 2017 at 10:14 UTC
    I will try to improve code quality! tnxx for that. But as far as padding, maybe I am wrong but, if I have say a 7 byte string at hand and I want it to be padded to 8 byte string I should add 1 byte i.e. 1 char say "0"... Correction: I think I get it now.... The char '0' in binary is far from being just seq. of 0 in bin!, and the DES algo' appends exactly those dec 0 you meant to the binary representation of a specific chunk.....? Hmm worth checking!! tnxx again:) Also found just now :( found this: https://asecuritysite.com/encryption/padding_des
      Also found just now :( found this: https://asecuritysite.com/encryption/padding_des