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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:11:29+00:00 2026-06-13T00:11:29+00:00

I have a program that XORs two files together using one time pad encryption.

  • 0

I have a program that XORs two files together using one time pad encryption. As the keyfile is of such sensitive nature I don’t want any traces of the keyfile to appear on the computers hard drive as that could compromise security.

The question is, how do I run the program in RAM so as to avoid any traces being left on the HD? Alternatively, will running the program from a flash drive contain traces of the keyfile to the flash drive?

Below is how the keyfile is treated in the program:

/* Check if keyfile can be opened. */
if((keyfile = fopen(argv[3], "rb"))== NULL)
{
printf("Can't open keyfile.\n");
printf("Please enter a valid filename.\n"); 
printf("USAGE: OTP <source file> <output file> <keyfile>\n");
perror("Error");
return(1);
}                               

/* Get size of keyfile */
fstat(fileno(keyfile), &keybuf);

/* Check if keyfile is the same size as, or bigger than the sourcefile */
if((keybuf.st_size) < (statbuf.st_size))
{
printf("Source file is larger than keyfile.\n");
printf("This significantly reduces cryptographic strength.\n");
printf("Do you wish to continue? (Y/N)\n");
fgets(buffer, 20, stdin);
sscanf(buffer, "%c", &ans);
if(ans == 'n' || ans == 'N')
{
return (1);
}
if(ans == 'y' || ans == 'Y')
{
    printf("Proceeding with Encryption/Decryption.\n");
    }

/* Encrypt/Decrypt and write to output file. */
while(count < (statbuf.st_size))
{
key=fgetc(keyfile);
data=fgetc(sourcefile);

output=(key^data);

fputc(output,destfile);
count++;
}

/* Close files. */
fclose(keyfile);
fclose(sourcefile);
fclose(destfile); 

I came across an inram function when googling this, but that didn’t seem to be what I needed.

  • 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-13T00:11:30+00:00Added an answer on June 13, 2026 at 12:11 am

    I assume you’re reading the keyfile from some external media and you are worried about the process being swapped to disk along with the I/O buffers containing the OTP. You are probably equally concerned about the plaintext being written. If you are on a posix system (like linux) then you should look into the mlock and mlockall functions. These calls will lock memory pages into RAM and prohibit their swapping to disk. The man page specifically calls out the security use case for these calls. Another option might be to mmap the files. Though it doesn’t carry the same guarantee, since the mapped pages will be backed by the external media I doubt they’d appear in the swap space.

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

Sidebar

Related Questions

I have a program that gets a JSON from the server using getJSON and
I have a program that encrypts files, but adds the extension .safe to the
I have a program that have 2 threads running at the same time. Every
I have a program that is accessing many similar tables using a linq to
I have program that sends a file to a printer using 'lpr' command. I
I have program that constantly query a mysql server. Each time I access the
I have program that runs for long periods of time and I'd like to
I have a program that I use to enter values into a database using
I have a program that uploads files to our server when they are dropped
I have a program that creates a Windows user account using the NetUserAdd() API

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.