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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:35:29+00:00 2026-05-25T23:35:29+00:00

I have been given a sample encryption module which simply xor a key with

  • 0

I have been given a sample encryption module which simply xor a key with the packet data and place the result in data field of constructed packet itself….

The code for xoricv module is here.

void
xorcrypto(uint8_t *key, uint32_t keylen,
    uint8_t *data, uint32_t datalen)
{
    int d, k;

    for (d=0, k=0; d < datalen; ++d, k = (k+1)%keylen) {
            data[d] ^= key[k];
    }
}

Now i need to change the module so that it performed the AES Encryption rather than simple xor operation.

Would you suggest possible transformation i need to do ????

It is a small part of my project and i am stuck in between..

The AES Command I have used on command line for encryption

openssl enc -aes-256-cbc -salt -in file.txt -out file.enc

Daily i am going through plenty of errors when i tried to implement it by my own and i have very limited time so please help me…….


Here is my implementation …… although i am adding it here in answer column because may be there is small bug in my implementation which i could be able to solve through some valuable suggestions but still If any other way is possible please suggest and provide me some implementation code…

/* u_int8_t ... etc all are typedefs for uint8_t....etc 
 so don't bother about them */

void xorcrypto(u_int8_t *key, u_int32_t keylen,u_int8_t *data,
               u_int32_t datalen)
{

int ch,i,j;
uint8_t modata[100];

FILE *fp,*fr,*fq,*ft;

fp=fopen("key","w");
fputs((char *)key,fp);
fq=fopen("file.txt","w");
fputs((char *)data,fq);

fclose(fp);
fclose(fq);

system("sudo openssl enc -aes-256-cbc -salt -in file.txt -out file.enc -pass file:key");

fr=fopen("file.enc","r");

memset(data,0,sizeof(data));

i=0;

while( (ch=fgetc(fr))==EOF) {
   data[i]=ch;
   i++;
}

fclose(fr);

system("sudo openssl enc -d -aes-256-cbc -salt -in file.enc 
 -out file1.txt -pass file:key");


ft=fopen("file1.txt","r");

memset(modata,0,sizeof(modata));

j=0;

while( (ch=fgetc(ft)) != EOF) {
            modata[j]=ch;
            j++;
}

fclose(ft);

}

Call to function in module is described as –

bool
espcrypto(esp_private *epriv, sendip_data *data, sendip_data *pack)
{
    u_int32_t keylen;
    u_int8_t *key;
    static u_int8_t fakekey;
    struct ip_esp_hdr *esp = (struct ip_esp_hdr *)pack->data;

    if (!epriv->keylen) {   /* This isn't going to be very productive... */
            key = &fakekey;
            keylen = 1;
    } else {
            key = (u_int8_t *)epriv->key;
            keylen = epriv->keylen;
    }
    /* Encrypt everything past the ESP header */
    xorcrypto(key, keylen,
            (u_int8_t *)esp->enc_data,
                    pack->alloc_len + data->alloc_len -
                            sizeof(struct ip_esp_hdr));
    return TRUE;
    }

This is code in the xorcrypto.c file in packet generator tool i am using which is linked during packet construction through command line as -am xorcrypto.so .That is the reason why I was being so lazy.I am first looking for an implementation which can act as proof of concept .Rest all optimizations can be done later.

The output I am getting is – encryption not performed at all the data is still in plain text in packet.

udit@udit-Dabba ~/Downloads/sendip-2.5-mec-2/mec $ cat file.txt 
udit@udit-Dabba ~/Downloads/sendip-2.5-mec-2/mec $ cat file.enc 
Salted__����
}�#��G�����0����iudit@udit-Dabba ~/Downloads/sendip-2.5-mec-2/mec $ cat file1.txt
udit@udit-Dabba ~/Downloads/sendip-2.5-mec-2/mec $ 

Why file.txt is null even key file is not updated ???

If any other information needed i will add it here……but please help me getting out of the mesh .

  • 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-05-25T23:35:30+00:00Added an answer on May 25, 2026 at 11:35 pm

    Well,

    I feel the line :

    while( (ch=fgetc(fr))==EOF)
    // Also, Similar statements that you have used many times.
    

    You are reading 1 character from the file and comparing that to EOF. That works fine untill you are working with normal text files.

    But here you are working with an encrypted file, file.enc which can contain anything at all.
    It can even posses EOF character itself as data content.

    That means if file has 100 characters and 2nd character is EOF then it will terminate at 2nd character itself.

    I feel this as a possible problem.

    Remains.. the other problems – I suggest using fprintf() instead of fputs(), these are easy to use and hence avoids unseen bugs. Since you are working on strings instead of characters logically.

    Moreover, using these you also get an advantage of string formatting when needed.

    Try out and then get back.. 🙂

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

Sidebar

Related Questions

I have been given a sample statement: MyClass myclass = 3; How is it
I have been given a requirement where I need to support multiple databases in
I have been given two different Microsoft Word document that my virus scanner has
I have been given a DLL (InfoLookup.dll) that internally allocates structures and returns pointers
I have been given the task of internationalizing a large client-server application. The remit
I have been given a specification that requires the ISO 8601 date format, does
I have been given the following request. Please give 7% of the current contacts
I have been given the option to either have a Windows laptop or a
I have been given the task of adding functionality to an existing IIS 6.0
I have been given the unenviable task of cleaning up after a developer who

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.