In ECB mode, the results of plaintext packet encryption are grouped directly as ciphertext, as shown in:
When using ECB mode encryption, the same plaintext groupings are converted to the same cipher groupings, that is, we can interpret them as a large "plaintext grouping → ciphertext grouping" table, so the ECB mode is also known as the electronic cipher mode.
ECB mode benefits:
1. Simple
2. Facilitates parallel computing
3. Error is not transmitted
ECB mode Disadvantages:
1. Cannot hide the clear text mode
2. Possible active attacks on plaintext
Attacks on the ECB model come from a book on graphic cryptography:
ECB mode encryption:
" "Suppose that the encryption is grouped into a group of 4 bytes" "defEncrypt (Strdata, key): Strendata="" forIinchRange (0, Len (strdata)):#Bitwise XOR or post-saverst = Ord (list (strdata) [i]) ^Ord (List (key) [i]) strendata= Strendata +chr (RST)returnStrendatadefDecrypt (Strdata, key): Strdedata="" forIinchRange (0, Len (strdata)):#re-xor or restorerst = Ord (list (strdata) [i]) ^Ord (List (key) [i]) strdedata= Strdedata +chr (RST)returnStrdedataif __name__=='__main__': Strdata="Hello world!"Key="1234"I=0 J= 4Strendata="" Print("Original data:%s\r\n"%strdata) whileTrue:strgroup=Strdata[i:j]ifStrgroup = ="' : BreakStrendata+=Encrypt (Strgroup, key) I+ = 4J+ = 4Print("after encryption:%s\r\n"%strendata) Strdedata=""I=0 J= 4 whileTrue:strgroup=Strendata[i:j]ifStrgroup = ="' : BreakStrdedata+=Decrypt (Strgroup, key) I+ = 4J+ = 4Print("after decryption:%s\r\n"%strdedata)
Original data: Hello world!
After encryption: Yw_x^d[c^w
After decryption: Hello world!
Block cipher mode: ECB mode (electronic password mode)