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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:33:32+00:00 2026-06-15T12:33:32+00:00

Again I have a problem with mcrypt. I am wondering why am I getting

  • 0

Again I have a problem with mcrypt. I am wondering why am I getting diffrent results in php and c bei encryping with rinjdael-128 cfb mode. Here is my php function:

function mcencrypt($Clear, $Pass){
$td = mcrypt_module_open('rijndael-128', '', 'cfb', '');
$iv = 'AAAAAAAAAAAAAAAA';
mcrypt_generic_init($td, $Pass, $iv);
$encrypted = mcrypt_generic($td, $Clear);
mcrypt_generic_deinit($td);
return $encrypted;
}

and my c function:

unsigned char *Encrypt( unsigned char *key, unsigned char *message, int buff_len){

    unsigned char *Res;
    MCRYPT mfd; 
    char* IV = "AAAAAAAAAAAAAAAA";
    int i, blocks, key_size=16, block_size;

    mfd = mcrypt_module_open("rijndael-128", NULL, "cfb", NULL);
    block_size = mcrypt_enc_get_block_size(mfd);
    blocks = ceil((double)buff_len/block_size);

    mcrypt_generic_init(mfd, key, key_size, IV);
    Res = calloc(1, (blocks *block_size)+1);

    strncpy(Res, message, buff_len);
    mcrypt_generic(mfd,Res,(blocks *block_size));

    mcrypt_generic_deinit(mfd);
    mcrypt_module_close(mfd);

     return (Res);

}

when I use them in a for loop the first 26 encryptions are korect, but at the 27 the last tree signs are diffrent. This is realy very odd.

in php I make the for loop like this:

$seed ="m78otPfBLT48msvd";
$key = "r2oE61IQo7VwFXnF";
$start_y= mcencrypt($seed,$key);
$new =$start_y;
$enc_prob = mcencrypt($start_y,$key);
for ($j=1; $j<30;$j++){
$new.=$enc_prob;
echo "j: ".$j.'<br>';
echo "the new: ".$enc_prob."lenght: ".strlen($enc_prob).'<br>';
echo "new in hex for j=".$j.": ".strToHex($enc_prob).'<br>';
$enc_prob=mcencrypt($enc_prob,$key);
}

and in c like this:

 int j, buff_len;
char seed[] = "m78otPfBLT48msvd", key1[]="r2oE61IQo7VwFXnF";
buff_len = strlen(seed);
unsigned char *encrypted, *encrypted2;
encrypted = Encrypt(key1, seed, buff_len);
encrypted2 =  Encrypt(key1, encrypted, buff_len);
for (j=1; j<cols; j++) {
    printf("j: %d\n", j);
    printf("encrypted2 %s\n", string_to_hex(encrypted2, buff_len));

    memcpy(encrypted2, Encrypt(key1, encrypted2, buff_len),buff_len);
}
free(encrypted);
free(encrypted2);

what is going wrong. The message and the key are the same. I’m using the same library, the same iv. I don’t get it. It is strange. Please help me out on this one. Many thanks in advance!!

  • 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-15T12:33:34+00:00Added an answer on June 15, 2026 at 12:33 pm

    I figured out what the problem was. The strings in c are null terminated and by using strncpy in my encryption function was making the problems, so I just changed that in memcpy and now everything goes well. Thanks again to everybody who tried to help and took time to take a look at my problem.

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

Sidebar

Related Questions

I have this problem again and again... and still have not a satisfactory answer...
Hello again everyone, This time I have a problem with Intent & Extras. here's
Once again I have a problem which I can't find the solution to. A
Hello again stackoverflow... Once again I have a troublesome problem. I have a page
Again I have problem with checking whether DataReader object has data or not? Dim
I again have a little problem. I have used ReportViewer in my Windows Form
I have problem with the Play Again button, which is to reset the panel
Once again I have a small problem to get this done in django. But
i have problem with closing saveFileDialog. when i click'cancel' window appears once again. here
I yet again have a super weird problem. I get different outputs whether I'm

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.