Block cipher mode: OFB mode (output feedback mode)

Source: Internet
Author: User

In the OFB mode, the output of the cryptographic algorithm is fed back into the input of the cryptographic algorithm, and the OFB pattern is not directly encrypted by the cipher algorithm, but by XOR the output of the plaintext packet and cipher algorithm to create the ciphertext grouping, at which point the OFB mode and the CFB mode are very similar, as shown in:

The difference between the OFB mode and the CFB mode is only the input of the cipher algorithm, in the CFB mode, the input of the cipher algorithm is the previous ciphertext grouping, that is, the cipher packet is fed back to the cipher algorithm, and the input of the cipher algorithm is the previous output of the cipher algorithm in OFB mode, which is the output feedback to the cipher algorithm. A grouping is drawn out to compare the CFB mode to the OFB mode, which makes it easy to see the difference:

Advantages of the OFB mode:

1. Clear text mode is hidden
2. Block password conversion to stream mode
3. Data that is smaller than the packet can be encrypted in time

ofb mode. Disadvantages:

1. Not conducive to parallel computing
2. Active attacks on plaintext are possible
3. Error transfer: A clear text unit damage affects multiple units

OFB Mode of encryption:

#include <string. H>#defineInch#defineOut//Suppose that the encryption is grouped into a group of 4 bytes/*************************************************************************** function: Encryption algorithm (with key XOR) * Parameter: Lpszdata Current plaintext Packet data * Lpszkey Key * Lpszdedata Encrypted result * * return value: ******************************* *******************************************/voidEncrypt (inConst Char*lpszdata, inConst Char*lpszkey, outChar*lpszendata) {    inti =0;  for(i =0; I <4; i++) {Lpszendata[i]= Lpszdata[i] ^Lpszkey[i]; }}/*************************************************************************** function: Current plaintext and current key stream xor * parameter: Lpszdata Current plaintext Packet data * Lpszkeystream current cipher algorithm output * Lpszxordata save XOR Data * * return value: **************************** **********************************************/voidXordata (inConst Char*lpszdata, inConst Char*lpszkeystream, outChar*lpszxordata) {    inti =0;  for(i =0; I <4; i++) {Lpszxordata[i]= Lpszdata[i] ^Lpszkeystream[i]; }}intMainintargcChar*argv[]) {    CharSzdata[] ="Hello world!"; Charszendata[ -] = {0}; Charszdedata[ -] = {0}; Char*lpszkey ="1234"; inti =0; CharSziv[] ="9999"; printf ("Original data:%s\r\n", Szdata);  while(true)    {        if(strlen (szdata + i) = =0)        {             Break; }        //the output of the cryptographic algorithmEncrypt (Sziv, Lpszkey, Sziv); //plaintext grouping and the output of the cipher algorithm do XORXordata (Szdata + i, Sziv, Szendata +i); I+=4; } printf ("post-encrypted data:%s\r\n", Szendata); memcpy (Sziv,"9999",4); I=0;  while(true)    {        if(strlen (szendata + i) = =0)        {             Break; }                //the output of the cryptographic algorithmEncrypt (Sziv, Lpszkey, Sziv); //ciphertext grouping and the output of cipher algorithm do XORXordata (Szendata + i, Sziv, Szdedata +i); I+=4; } printf ("post-decryption data:%s\r\n", Szdedata); return 0;}

Raw data: Hello world!
Post-encryption data: @nfaVnVzgn,
Decrypted data: Hello world!

Block cipher mode: OFB mode (output feedback 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.