python - Why can I encrypt data with one DES key and successfully decrypt with another? -


I tried to apply DES algorithm using PEDS and crypto seagr. DES module. I had a problem when I 82514145 would extend encrypted with the key and cipher to decrypt the 93505044 , I can retrieve the decrypted text. I had 256 keys behaved this way, it is a violation of cryptography. My code is as follows:

  from crypto Import DES plain_text = 'asdfghij' Print 'plain text:', plain_text des = DES.new ( '82514145', DES.MODE_ECB) cipher_text = des.encrypt (plain_text) print "ciphertext" Saifr_tekst DES = DES. New (9 '3505044', Diiskmood_isibi) print "decrypted text:" dES Dikrript (Saifr_tekst)   

output:

  plain text: asdfghij the ciphertext @ ¿½ ¿½ ï ¿½ ï ¿½ ¿½ decrypted text: asdfghij   

what about my In any mistakes? I got the same results with PID.

DES keys are only 56 bits long, but they are expanded thanks to 64 bit equality bits The eighth bit of each byte should be set to ensure.

Many crypto libraries ignore parallel bits, which means that there are several ways to represent the same 56-bit key in a 64-bit key string. In fact, 2 8 are different ways, which tells you why you got 256 matching keys.

Your example contains two key values ​​that are only different in similarity bits. See below - the parity bits [] :

  82514145 = 0x3832353134313435 = 0011100 [0] 0011001 [0] 0011010 [1] 0011000 [1] 0011010 [0] 0011000 [0] 0011010 [0] 0050000 = 0x3933353035303434 = 0011100 [1] 0011001 [1] 0011010 [1] 0011000 [0] 0011010 [1] 0011000 [0] 0011010 [0] 0000000 [0]   

Neither the key is actually valid indeed. The correct representation of that key is: 0x3832343134313401 .

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -