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

  • Home
  • SEARCH
  • 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 9075313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:50:08+00:00 2026-06-16T18:50:08+00:00

read 16 bytes from a file; encrypt this 16 bytes; write encrypted bytes to

  • 0
  • read 16 bytes from a file;
  • encrypt this 16 bytes;
  • write encrypted bytes to another file;
  • do the above things again until end of file;

If the last call is < 16 bytes i fill the buffer with 0.
Is this a correct way to do it?

FILE *fp = fopen("name", "r+");
FILE *fpout = fopen("name", "w+");
char plain_text[16];
fseek(fp, 0, SEEK_SET);

while(!feof(fp)){
  memset(plain_text, 0, sizeof(plain_text);
  read_bytes = fread(plain_text, 1, 16, fp);
  if(read_bytes < 16){
    i = read__bytes;
    read_bytes += 1;
    for(i, i<16, i++) plain_text[read_bytes] = 0;
  }
  encrypt-this-part-of-file
  fwrite(encBuffer, 1, 16, fpout);
}
  • 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-16T18:50:09+00:00Added an answer on June 16, 2026 at 6:50 pm

    no, this would be correct…

    if(read_bytes < 16)
    {
        for(i = read_bytes; i<16; i++)
        {
            plain_text[i] = 0;
        }
    }
    

    …if you’d actually needed it.

    But you don’t need to zero the remaining part of the array as you have already cleared it with…

    memset(plain_text, 0, sizeof(plain_text));
    

    …that you’re calling before each invokation of fread.

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

Sidebar

Related Questions

I want to read bytes from a file and then write those bytes to
I'm doing a steganography project where I read in bytes from a ppm file
I have dynamic array filled with bytes, which are read from .raw file with
I want to read bytes from a wave file into an array. Since the
I wanted to read bytes from file and then rewrite them. I did like
I have a huge binary file from which I want to read some bytes
I want to read N bytes of data from a file stream and append
I am trying to read bytes of image from the XML file but I
Is there any way to read specific bytes from a file? For example, I
i have this RandomAccessFile object that reads bytes from a file and stores them

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.