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 8188249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:50:36+00:00 2026-06-07T02:50:36+00:00

For a school project, I’m writing a blowfish encryption (just the encryption, not the

  • 0

For a school project, I’m writing a blowfish encryption (just the encryption, not the decryption). I’ve finished the encryption itself, and I decided I would do the decryption for fun (it’s easy enough in Blowfish).

I used unsigned chars to represent bytes (although I suppose uint8_t would have been more portable). The question I have comes in when I am attempting to print out the decrypted bytes. I am encrypting plain text messages. I’ve been able to print out the actual text message that I encrypted, but only at a very specific spot. The same exact code seems not to work anywhere else. Here it is:

int n;
for(n = 0; n < numBlocks; n++) // Blocks are 32-bit unsigned ints (unsigned long)
{
     // uchar is just a typedef for unsigned char
     // message is an array of uchars
     message[n] = (uchar) ((blocks[n]>>24));
     message[n+1] = (uchar) ((blocks[n]>>16));
     message[n+2] = (uchar) ((blocks[n]>>8));
     message[n+3] = (uchar) ((blocks[n]));
     // Printing works here; exact message comes back
     printf("%c%c%c%c", message[n], message[n+1], message[n+2], message[n+3]); 
}

But when I try to use the exact same code two lines later, it doesn’t work.

for(n = 0; n < numBlocks; n++)
{
     // Printing doesn't work here.
     // Actually, the first letter works, but none of the others
     printf("%c%c%c%c", message[n], message[n+1], message[n+2], message[n+3]); 
}

I have tried printing out the characters in number format as well, and I can see that they have in fact changed.

What exactly is going on here? Is this undefined behavior? Does anyone have any reliable solutions? I’m not doing anything to change the value of the message array in between the two calls.

I’m running and compiling this on Sun 5.10 with a sparc processor.

  • 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-07T02:50:38+00:00Added an answer on June 7, 2026 at 2:50 am
    for(n = 0; n < numBlocks; n++) // Blocks are 32-bit unsigned ints (unsigned long)
    {
         message[n] = (uchar) ((blocks[n]>>24));
         message[n+1] = (uchar) ((blocks[n]>>16));
         message[n+2] = (uchar) ((blocks[n]>>8));
         message[n+3] = (uchar) ((blocks[n]));
    }
    

    Every time you go through this loop, you set message[n] to message[n+3], then increment n by 1. This means that your first iteration sets message[0], message[1], message[2] and message[3], then your second sets message[1], message[2], message[3] and message[4]. So basically, you overwrite all but the first char in your message on every iteration.

    Most likely you need to make message 4x larger and then do:

    message[n*4] = ...
    message[n*4 + 1] = ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For my school project, I would like to build a gui that someone else
A school project has me writing a Date game in C++ (example at http://www.cut-the-knot.org/Curriculum/Games/Date.shtml
I'm currently working on a school project in Eclipse (We have just started using
While doing a minor school project, I just noticed a difference in the range
I have a school project I'm not supposed to be starting til monday, and
Im currently writing a database for a school project. Im using MySQL on xampp
For my school project, I try to make a form in Zend. I would
I'm working on a school project in which we would like to analyze the
For a school project, I am writing an iOS iPad application in which the
I'm writing a program for a school project that is supposed to emulate the

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.