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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:54:28+00:00 2026-06-13T07:54:28+00:00

I have written some code, and the Vigenere encryption is used in it. This

  • 0

I have written some code, and the Vigenere encryption is used in it. This is a simple program for encrypting/decrypting any files.

#include<stdio.h>
/*
LANGUAGE: C.
STANDARD: C89.

ABOUT PROGRAM:
This is a simple program for encrypting/decrypting any files.
The size of source file coincide with size of result file.
For encryption of file are use any string key. For decrypting, 
you must to use the same key, which was used for encryption.

NOTES:
The Vigenere encryption are used in it. 
Info at the site: http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher.
This simple algorithm is often used at commercial products. The 
Vigenere's algorithm are using a string key, and 'XOR' for 
encrypting/decrypting information.

WARNING!
The use of this method, doesn't give 100% of a warranty 
for protection of your information. Don't create the keys, 
consisting of identical characters, for example" "aaaaa", 
"zzz", "xxxx" e.t.c. - it is very feeble protection!
Don't forget your encrypting keys... :)

SYNTAX OF USING:

vigenere StringKey SourceFileName ResultFileName

where:
vigenere - program name;
StringKey - string key for encrypting/decrypting;
SourceFileName - source file name;
ResultFileName - result file name;

EXAMPLE OF USING:
vigenere "G5$hj4*df7f3+x" "c:\temp\source.txt" "c:\temp\result.txt"

*/
int main(int argc, char *args[]){
    /****************************************************/
    /* All variables must be defined on top in function, otherwise 
    some compilers can't compile this code (for example - MS 
    Visual Studio 2012. */
    char ch; /* The next char for encrypting/decrypting. */
    char *x; /* String key. */
    FILE *srcFile; /* Source file. */
    FILE *trgFile; /* Result file. */   
    /****************************************************/

    /* The first argument always is a program file name. */
    if (4 != argc)
        return 1; /* Invalid arguments count. */

    if (!*args[1] || !*args[2] || !*args[3])
        return 2; /* Contains the empty argument. */

    x = args[1];
    if ((srcFile = fopen(args[2], "rb")) != NULL){
        if ((trgFile = fopen(args[3], "wb")) != NULL){          
            while((ch = getc(srcFile)) != EOF){
                if(!*x++)
                    x = args[1];
                putc((ch ^= *x), trgFile);
            }           
            fclose(trgFile);
        }
        else
            return 4;  /* Result file wasn't created. */
        fclose(srcFile);
    }
    else
        return 3; /* Source file wasn't opened. */
    return 0; /* Successful operation. */
}

But this code does not always work well. I don’t understand why it occurs. I do XOR for each byte. I have tested this code on such TXT files. Where is my mistake?

  • 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-13T07:54:29+00:00Added an answer on June 13, 2026 at 7:54 am
     char ch;
    
     /* ...  */
    
     while((ch = getc(srcFile)) != EOF)
    

    ch must be an int. EOF is defined as a negative int.

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

Sidebar

Related Questions

I have written some code in JSP to download .docx files which is hosted
I have written some code which produces simple animations based on cycling through a
I have written some code there are 27 different functions that execute like this..
I have written some code that used strings to represent time such as 0620,
I have written some code and used a string that I concatentated using the
I have written some code in Lib_file.h and Lib_file.cpp. I wish to convert this
I have written some code that looks more or less like this: QVector<QRgb> colorTable(256);
I have written some code that loads an XML document using an XmlDocument object
I have written some code for displaying a drop down list, but the code
I have written some code for playing a .wav through my application. Now I

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.