473,414 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

C programming incorrect encrypting while loop

this main is supposed to receive user input (file names, flags and a keyword), then encrypt the file according to the user input, then close the file pointers. however it goes wrong for some reason. All of the functions have been independantly tested and work but the main fails.

when i first run the program (in the while loop) it encrypts the data properly. and if i quit the while loop and restart the program it will decrypt it properly.

Although when i encrypt the data (and stay in the while loop) then try and decrypt it immediately following it fails to decrypt it properly. no idea why...?

Expand|Select|Wrap|Line Numbers
  1. int main(void)
  2. {
  3. char dataInput[BUFSIZE], dataOutput[BUFSIZE], keyword[BUFSIZE];
  4. int flags[NFLAGS];
  5. flags[QUIT] = 0;
  6. flags[HELP] = 0;
  7.  
  8. while (flags[QUIT] != 1)
  9. {    
  10.     while (parse_user_input(dataInput, dataOutput, keyword, flags) == 0)
  11.         printf("Error: Invalid input. type h for help.\n");
  12.  
  13.     if (flags[QUIT] == 1)
  14.         break;
  15.  
  16.     else if (flags[HELP] == 1){
  17.         help_message(flags[HELP]);
  18.         flags[HELP] = 0;
  19.     }
  20.  
  21.     else
  22.     {
  23.         FILE *fin, *fout;
  24.         if (flags[SEED] == 0){
  25.             int i;
  26.             for (i = 0; keyword[i] != NUL; ++i)
  27.             flags[SEED] = keyword[i] + 31*flags[SEED];
  28.             }
  29.  
  30.         fin = open_file(dataInput, 0);
  31.         fout = open_file(dataOutput, 1);
  32.  
  33.         if (fin == 0 || fout == 0)
  34.             printf("Error opening file");
  35.         else
  36.         {
  37.         ranf_start(flags[SEED]);
  38.  
  39.         encrypt(fin, fout, keyword, flags[MODULO]);
  40.  
  41.         fclose(fout);
  42.         fclose(fin);
  43.         }
  44.     }
  45.  
  46. }
  47. return 0;
  48. }
  49.  
any advice would help a lot. Final step of my project!!!
Sep 13 '09 #1
2 2790
Banfa
9,065 Expert Mod 8TB
I do not see any way in which this program would ever decrypt data unless your encryption algorithm happened to be ROT13
Sep 13 '09 #2
JosAH
11,448 Expert 8TB
@Banfa
... or any other encryption method that is involutary, i.e. E(x) ==E^-1(x), so E(E(x)) == x.

kind regards,

Jos
Sep 13 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Dayne | last post by:
Guys, I am writing a database application(vb.net , sql server) and is presently storing the connection settings in a xml file...not very secure though. What is a safer method in a dynamic...
46
by: dawn | last post by:
Hi all, I am now working on a C program under Unix. The requirement for the program is that: A file name is passed to program as a parameter. The program will Find files under a specified...
20
by: Hugo | last post by:
Hi Y'All... I really need your help!! I've used this groups to learn and get me out of troubles but this is my first time writing a subject. My problem is that I need to make a C program...
22
by: Sharrukin Amiri | last post by:
Can anyone give me a head start on programming outlook to send and recieve mail via VB 2005. I want to automatically send a unique pin number to a customer who's credit card was approved. I am...
1
by: ndawg123 | last post by:
Hey guys what im trying to do is write a yatzee game with C. And im stuck already and its the start?!?! I want the user to type there 5 numbers. i.e My program so far does this Please...
2
by: SeeSharp Bint | last post by:
Visual Studio 2005, dotnet, c#. Microsoft SQL Server. Windows XP forms application. Temporarily, for my database application, I have been storing the various elements of database connection...
4
by: per9000 | last post by:
Hi python people, I am trying to figure out the best way to encrypt files in python. I've build a small script (see below) that encrypts the ubuntu 7.04 iso file in 2 minutes (I like python :)...
23
by: Dexter | last post by:
My site is home to series of quizzes ranging from Accounting, Business, Math to programming languages. These are multiple choice type questions and you get a score card at end. For C language, ...
43
by: Adem24 | last post by:
The World Joint Programming Language Standardization Committe (WJPLSC) hereby proclaims to the people of the world that a new programming language is needed for the benefit of the whole mankind in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.