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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:26:40+00:00 2026-06-12T16:26:40+00:00

I’m trying to create a long string that is produced out of encrypted substrings.

  • 0

I’m trying to create a long string that is produced out of encrypted substrings. For the encryption I’m using AES128 and libmcrypt. The code is working, but I get a shorter output then I should and a beeping sound. I guess it’s because I’m using strlen, but I have no idea, how I can avoid that. I will be very grateful for some suggestions. Here is my code:

char *Encrypt( char *key, char *message){   
    static char *Res;
    MCRYPT mfd;
    char *IV;
    int i, blocks, key_size = 16, block_size = 16;
    blocks = (int) (strlen(message) / block_size) + 1;

    Res = calloc(1, (blocks * block_size));

    mfd = mcrypt_module_open(MCRYPT_RIJNDAEL_128, NULL, "ecb", NULL);
    mcrypt_generic_init(mfd, key, key_size, IV);

    strncpy(Res, message, strlen(message));
    mcrypt_generic(mfd, Res, block_size);
    //printf("the encrypted %s\n", Res);

    mcrypt_generic_deinit(mfd);
    mcrypt_module_close(mfd);

     return (Res);
}

char *mkline ( int cols) {
    int j;
    char seed[] = "thesecretmessage", key1[]="dontusethisinput", key2[]="abadinputforthis";

    char *encrypted, *encrypted2, *in = malloc(cols * 16);
    encrypted = Encrypt(key1, seed);
    sprintf(in, "%s", encrypted);
    encrypted2= Encrypt(key2, encrypted);
    printf("encrypted2 before for-loop %s\n", encrypted2);
    printf("encrypted2 before for loop len %d\n", strlen(encrypted2));
    for (j=1; j<cols; j++) {
        strcat(in, encrypted2);
        memmove(encrypted2, Encrypt(key2, encrypted2),strlen(seed));
        printf("encrypted2 %s on position %d\n" , encrypted2,j);
        printf("encrypted2 len %d\n", strlen(encrypted2));
    }
    free(encrypted);
    free(encrypted2);
    return in;
}

int main(int argc, char *argv[]) {
    char *line = mkline(15);
    printf("line %s\n", line);
    printf("line lenght %d\n", strlen(line));
    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-12T16:26:42+00:00Added an answer on June 12, 2026 at 4:26 pm

    You get the beep sound because you are printing control character.

    Also strlen return the size until the first ‘\0’ character (because strings are zero terminated). That’s why you get length less than you expect since the encrypted message may contain zeroes.

    You can do something like this to return the result length:

     char *Encrypt(const char *key, const char *message, int *result_len)
     {
       *result_len = blocks * block_size;
     }
    

    Also

    memmove(encrypted2, Encrypt(key2, encrypted2),strlen(seed));
    

    This line should produce a memory leak since every time you call Encrypt you call calloc (allocate new memory) which you need to free after you are done.

    You probably should use memcpy, memmove is primarly used if there is a chance destination and source may overlap.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is

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.