Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8079093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:59:49+00:00 2026-06-05T15:59:49+00:00

I am trying to code AES using Cipher Block Chaining(CBC) mode. I am pretty

  • 0

I am trying to code AES using Cipher Block Chaining(CBC) mode. I am pretty sure that I have the structure correct (xoring the previous ciphertext with the new plaintext before sending it to AES and the reverse when I decrypt. The problem I am having is with decrypting the encrypted file back to the original plaintext. I think it might have something to do with the way that it is xored. I know that my AES algorithm is correct. I xor two character arrays together. I know that if you take the results of xoring two things together and then xor one of them back with the answer, you should get the other operand back. However, when I check that functionality, it does not work like that.

Where I read it in the plaintext and xor it with the previous ciphertext

//THERE IS A RANDOM INITIALIZATION VECTOR BEFORE GETTING INTO THE WHILE LOOP
    while ((bytes_in = (read(fin, plaintext, AES_BLOCK)) ))
    {   
      for (count = 0; count < AES_BLOCK; count++){
        xor[count] = (plaintext[count]) ^ (ciphertext[count]);
        }   
       //AES STUFF NOT SHOWN SO THERE ISN'T MUCH CODE
      status = write (fdsk, ciphertext, strlen (ciphertext));
      for (count =0; count < AES_BLOCK; count++)
        plaintext[count] = '0';
    }

The decrypting part:

bytes = read(fin, previous_CT, AES_BLOCK); //reads in the initialization vector
while(total_bytes < aes_length)
{
 bytes = read(fin, ciphertext, AES_BLOCK);
 for(count = 0; count < AES_BLOCK; count++){
  plaintext[count] = (xor[count]) ^ (previous_CT[count]);
  printf("plaintext %d", plaintext[count]);
 }
}

To sum up my problem/question:
I’m wondering if there is something to xoring characters that I am not aware I need to do. It seems like I am doing it the correct way but for some reason I am not getting the correct results. I am also wondering if it could be the way I am reading the information in that is messing up my program. Please help me out!
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:59:50+00:00Added an answer on June 5, 2026 at 3:59 pm

    The bug that jumps out at me is on this line:

      status = write (fdsk, ciphertext, strlen (ciphertext)); // bug here
    

    I’m pretty sure you really want:

      status = write (fdsk, ciphertext, AES_BLOCK);
    

    Both versions may produce the same results much of the time, but occasionally a cipher produces the byte ‘\0’ somewhere in the middle of the ciphertext, and then the first buggy version truncates the write to something shorter than you wanted.
    (The same problem occurs in XORing "Hello World!" cuts off string ).

    I get all 0’s from the xor operation

    That only happens when you have exactly the same values on the left and right side of the XOR operation.
    Are you maybe accidentally copying data into the wrong buffer, or prematurely copying data for later use, ending up with a duplicate copy of data on the left and right side?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to encrypt a string with AES 128 encryption, using CBC mode,
i have this code trying to print an image in an html using session
I am trying to make a program that Encrypts data using AES, then encrypts
I am trying to write encrypt/decrypt methods for AES 256 CBC encryption using PKCS5Padding
I have written a BlackBerry app that uses AES encryption. I am trying to
I'm trying to implement AES encryption in my application. I have the following code
I have a CryptoAPI code to encrypt\ decrypt given data using AES-128 and a
I'm trying to perform AES encryption in CBC mode with zero padding. Does anyone
I am trying to write some code that does AES decryption for an SSL
Im trying to code a popup but I ran into some problems when using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.