i have to read the binary data of a file, then encrypt them according to a supplied algorithm...and then the obtained output has to be written to an output file...everythi ng works ok, and there are no errors...
but when i print out the binary data from the input file it seems to be the same whtever the file, and then after encrypting and wirting the data to the output file, the output file has a size of 0KB and nothing in it..pls help as soon as possible as i hav to submit assignment asap!!!!!
here is my code -
#include<stdio.h>
-
#include<ctype.h>
-
#include<string.h>
-
#include<stdlib.h>
-
-
FILE *finput, *foutput;
-
-
int main()
-
{
-
char input_file[255],output_file[255],keyword[1000];
-
int seed_val=0,help=0;
-
int i = 0,input_char[] = {0},s = 0,rand_char = 0,output_char[] = {0},key_length,encrypt_char,n;
-
-
-
printf("Enter the input file:"); /*Prompt user for input file name and location*/
-
fgets(input_file,255,stdin);
-
input_file[strlen(input_file)-1] = '\0';
-
-
for (; i < strlen(input_file); i++)
-
printf("%c", input_file[i]);
-
-
finput = fopen(input_file,"rb");
-
-
if (finput == NULL) /*Check whether input file exists, if not keep on asking for input file, until user enters correct input file*/
-
{
-
printf("\nError opening input file,please enter another file:");
-
while (finput == NULL)
-
{
-
printf("\nError opening input file,please enter another file:");
-
printf("\nEnter the input file:");
-
fgets(input_file,255,stdin);
-
input_file[strlen(input_file)-1] = '\0';
-
-
for (; i < strlen(input_file); i++)
-
printf("%c", input_file[i]);
-
-
finput = fopen(input_file,"rb");
-
}
-
printf("Input file opened successfully\n");
-
}
-
else printf("Input file opened successfully\n");
-
-
printf("\nEnter the output file:"); /*Prompt user for output file name*/
-
fgets(output_file,30,stdin);
-
output_file[strlen(output_file)-1] = '\0';
-
-
i = 0;
-
-
for (; i < strlen(output_file); i++)
-
printf("%c", output_file[i]);
-
-
foutput = fopen(output_file,"rb"); /*Open output file as an input file in order to check*/
-
-
if (foutput != NULL)
-
{
-
printf("\nOutput file already exists.");
-
fclose(foutput);
-
}
-
else printf("\nOutput file does not exist");
-
-
printf("\nEnter the keyword:");
-
fgets(keyword,30,stdin);
-
keyword[strlen(keyword)-1] = '\0';
-
-
for (; i < strlen(keyword); i++)
-
printf("\nThe keyword is %c", keyword[i]);
-
-
printf("%s",keyword);
-
-
printf("\nEnter seed generator value:");
-
scanf_s("%d",&seed_val);
-
printf("%d\n",seed_val);
-
-
/* Read Binary Data from input file*/
-
-
-
fread(input_char,sizeof(finput),100000000,finput);
-
printf("%d\n",input_char);
-
-
/*Seed Random number generator and generate random numbers*/
-
-
if (seed_val == NULL)
-
{
-
srand(s);
-
}
-
else (srand(seed_val));
-
-
key_length == strlen(keyword); /*Find length of keyword*/
-
-
for (i = 0; i < strlen(input_char);)
-
{
-
encrypt_char = input_char[i];
-
rand_char = rand();
-
i = (i + 1) % key_length;
-
n = 0;
-
output_char == encrypt_char ^ rand_char ^ keyword[i];
-
fwrite(&output_char,sizeof(output_char),10000,foutput);
-
}
-
-
foutput = fopen(output_file,"wb");
-
-
fclose(foutput);
-
fclose(finput);
-
-
-
-
-
}
-
1 3615 JosAH 11,448
Recognized Expert MVP
You're trying to open your output file using the "rb" flags; that doesn't open a
file for writing.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Joseph |
last post by:
Hi all,
I was wondering if there is any lib or function could do the following
things:
input: a char
output: 8 digits binary presentation for that given char
Example:
|
by: Steven T. Hatton |
last post by:
§27.4.2.1.4 Type ios_base::openmode
Says this about the std::ios::binary openmode flag:
*binary*: perform input and output in binary mode (as opposed to text mode)
And that is basically _all_ it says about it. What the heck does the binary
flag mean?
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in...
|
by: wwj |
last post by:
void main()
{
char* p="Hello";
printf("%s",p);
*p='w';
printf("%s",p);
}
|
by: anirudhvr |
last post by:
Hi,
I needed a basic binary to ascii encoder, so I wrote this piece of
code:
/*
Encoding algo: suppose 11111010 is the byte to be encoded.
It is first broken up into two 4-bit parts (1111 and 1010)
This 4-bit quantity is then padded between a 01 and a 10, ie,
01xxxx10 will be written out to the output file.
|
by: Fredrik |
last post by:
How can I download a binary file (like .doc or .pdf) from http to my
harddrive using the .net framework?
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
objResponse = objRequest.GetResponse();
BinaryReader bsRead = new BinaryReader(objResponse.GetResponseStream()
FileStream fs = new FileStream("test.doc", FileMode.CreateNew);
while(bsRead.PeekChar() != -1)
{
cbuf=bsRead.ReadByte();
| |
by: Hemang Shah |
last post by:
Hello fellow Coders!
ok, I"m trying to write a very simple application in C#. (Yes its my first
program)
What I want to do is :
1) Open a binary file
2) Search this file for a particular string.
3) Close the file
|
by: Adam J. Schaff |
last post by:
I am writing a quick program to edit a binary file that contains file paths
(amongst other things). If I look at the files in notepad, they look like:
<gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish>
etc.
I want to remove the "g:\" from the file paths. I wrote a console app that
successfully reads the file and writes a duplicate of it, but fails for some
reason to do the "replacing" of the "g:\". The code...
|
by: Mark |
last post by:
Hello.
I am attempting to write binary data from a file to an
OLE Object field, and then write the file back out from
the database. I am reading and writing the files in
binary mode, and using GetChunk and AppendChunk to read
and write binary data from the OLE Object field. I am
using VBA and DAO for this experiment. The OLE Object
field is being used to store Long Binary data.
|
by: Michael |
last post by:
I have a solution for this, but it feels wrong. If anyone could offer
a better one, I'm all ears. (Or technically, eyes.)
Basically, I have a bunch of classes. For concreteness, one is a
Matrix class, but that's only one example, so please don't get too hung
up on it.
I need to output and input these classes. I'd like a nice, pretty,
human readable output, something like:
1 2 3
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |