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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:39:18+00:00 2026-06-14T20:39:18+00:00

I would like to encrypt a text with Bruce Schneier’s class that was converted

  • 0

I would like to encrypt a text with Bruce Schneier’s class that was converted to c++ code by Jim Conger After the encryption I would like to decrypt the encrypted text. To try this out, I am using files for it. I’ve created a sample project, but the decrypted file isn’t contains the same text as the initial file. What can be the problem?

Here’s the download link for the blowfish class files.

I’ve created a Command line tool project in XCode and changed the main.m file to main.mm. Here you can find my contents of the main.mm file:

#import "blowfish.h"
#include <stdlib.h>
#include <stdio.h>

#define my_fopen(fileptr, filename, mode) \
fileptr = fopen(filename, mode); \
if (fileptr == NULL) { \
fprintf(stderr, "Error: Couldn't open %s.\n", filename); \
exit(1); \
}

const char *input_file_name = "test.txt";
const char *encoded_file_name = "encoded.txt";
const char *decoded_file_name = "decoded.txt";
unsigned char key[] = "thisisthekey";

int main(void) {
    FILE *infile, *outfile;
    int result, filesize;
    const int n = 8; // make sure this is a multiple of 8
    const int size = 1;
    unsigned char input[n], output[n];

    CBlowFish bf;
    bf.Initialize(key, sizeof(key)-1); // subtract 1 to not count the null terminator

    my_fopen(infile, input_file_name, "rb")
    my_fopen(outfile, encoded_file_name, "wb")

    filesize = 0;
    while (result = fread(input, size, n, infile)) {
        filesize += result;
        fwrite(output, size, bf.Encode(input, output, result), outfile);
    }

    fclose(outfile);
    fclose(infile);

    my_fopen(infile, encoded_file_name, "rb")
    my_fopen(outfile, decoded_file_name, "wb")

    while (result = fread(input, size, n, infile)) {
        bf.Decode(input, output, result);
        fwrite(output, sizeof(output[0]), filesize < result ? filesize : result, outfile);
        filesize -= result;
    }

    fclose(outfile);
    fclose(infile);

    return 0;
}
  • 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-14T20:39:19+00:00Added an answer on June 14, 2026 at 8:39 pm

    You’re using a block cipher with padding (look at the source code to CBlowFish::Encode) to encrypt a stream. You can’t do that because the decryption operation will have no way to know what constitutes a padded chunk that it should decrypt.

    For example, say you’re encrypting “FOOBAR”, but you read “FOO” the first time and this encrypts to “XYZZY”. Then you encrypt “BAR” to “ABCDE”. Your written file will contain “XYZZYABCDE”. But is that “XY” “ZZYA” “BCDE”? Or one block, “XYZZYABCDE” or what?

    If you want to encrypt a stream, use a stream cipher. Or if you want to cut it into arbitrary blocks, you have to preserve the output block boundaries so you can decrypt the blocks.

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

Sidebar

Related Questions

Hi i would like to know best encryption technique for text file encryption and
I have a method in my static Encryption class that looks like this: public
Which symmetrical encryption algorithm to use to encrypt e-mail address(short message)? I would like
i would like to create an application that encrypts a file (say text file)
We would like to use SQL Server Encryption to encrypt a couple of columns
I would like to encrypt and decrypt a password using 128 bit AES encryption
I would like to encrypt a string ( user's email ) and always obtain
I have a dictionary object which i would like to encrypt, then put it
Would like a for loop in jquery so that: For every hover_link: show hidden
Would like to make anapplication in Java that will not automatically parse parameters used

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.