473,569 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C programming incorrect encrypting while loop

7 New Member
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 2796
Banfa
9,065 Recognized Expert Moderator Expert
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 Recognized Expert MVP
@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
2080
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 environment? Dayne
46
2483
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 directory. The matched file must have the same content with the given file. It does not matter whether the filenames are the same. It is easy to find...
20
2664
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 that run in DOS and comunicates to another program made in VB.Net 2005. I used Borland C++ 5.02 but I´m not even sure if it would run in DOS.
22
2715
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 new to VB2005. This would be my first VB2005 app. I have using VB6 for over 15 years. -- Warm Regards,
1
2379
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 enter dice Values:
2
2267
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 items like datasource,password,userid as plain strings in the registry. I'd now like to make these secure against people reading them. I thought of...
4
2311
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 :) ). But I have some thoughts about it. By pure luck (?) this file happened to be N*512 bytes long so I do not have to add crap at the end - but...
23
3622
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, I have 3 set of quizzes that anyone is welcome to try online for free. Questions on C quizzes are rather easy to solve for Professional C...
43
3640
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 the 21st millenium. This new language not only differs from existing ones by new features and paradigms but which also brings real advantage by...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7982
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.