Block cipher mode: ECB mode (electronic password mode)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.