C++ :: Encryption Of File (Docx / PDF)
Apr 28, 2013
I have been assigned a project by my teacher to make a program in c++ which will be able to encrypt a text file, a .docx file or a pdf document !!! Encrypting a text file is easy i have already done that but how do i encrypt a docx file or a pdf file ???
View 2 Replies
ADVERTISEMENT
Dec 3, 2013
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int encrypt_data(FILE *);
[Code] ....
I am trying encrypt the file "encrypt" when I enter it I get "Error in reading file"
I think its a problem with the fgets() and scanf()...I tried both fgets out and then scanf but I get the same error.
I look in the directory and see that when I enter a file to be encrypted a blank file with a "?" at the end is created in the directory. so I try to encrypt "encrypt" it shows error then creates "encrypt?"
I then tested it by entering a random file name that does not exist
EXAMPLE
Please enter file to be encrypted: fakefilename
Error in reading file.
I look in the directory the non existent file now is listed "fakefilename"
View 1 Replies
View Related
Apr 23, 2014
I am writing a program for AES Encryption which is all but done as far as that the program encrypts the text and prints the encrypted text in the command prompt:
void main() {
int a;
unsigned char CipherKey[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
unsigned char PlainText[16] = {0x32, 0x43, 0xF6, 0xA8, 0x88, 0x5A, 0x30, 0x8D, 0x31, 0x31, 0x98, 0xA2, 0xE0, 0x37, 0x07, 0x34};
for(a=0;a<16;a++)
[Code] ....
Encrypted text output on command prompt = 39 25 84 1d 02 dc 09 fb dc 11 85 97 19 6a 0b 32
However, my project asks to "read blocks of data from a data file". Therefore I need to alter the main function to read the following arrays from a data file.
Unsigned char CipherKey[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
unsigned char PlainText[16] = {0x32, 0x43, 0xF6, 0xA8, 0x88, 0x5A, 0x30, 0x8D, 0x31, 0x31, 0x98, 0xA2, 0xE0, 0x37, 0x07, 0x34};
Firstly, I don't know how to take each individual part in the data file to store into each byte in the array i.e. 0x2B into CipherKey[0] of the array.
Secondly, How do I deal with the fact that each byte is in hexidecimal? How should my data file look?
this is what my data file Input.dat looks like at the minute:
0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
0x32, 0x43, 0xF6, 0xA8, 0x88, 0x5A, 0x30, 0x8D, 0x31, 0x31, 0x98, 0xA2, 0xE0, 0x37, 0x07, 0x34
The first line being the CipherKey array and the second being PlainText. I'm not sure if the '0x' or the commas are required.
I basically want to take the data from a file, store them in arrays in the program itself, encrypt the Input array PlainText and create a new file with the encrypted output array stored in it (I will deal with this part of the program after I get the input file done first).
View 6 Replies
View Related
May 31, 2012
I am currently using a byte encryption in C# which gets decrypted in my C++ client.
It is XOR, but I can't get it to work. Is there anything that Im doing wrong?
I already wrote the C++ XOR in C#, which look pretty much the same.
C#
Code:
public byte[] XOR(byte[] strng, byte[] key) {
int string_len = strng.Length;
int key_length = key.Length;
int i, position;
for (i = 0; i < string_len; i++) {
position = i % key_length;
[code]....
View 14 Replies
View Related
Jun 15, 2014
what i think i need to create 2 int for the FOR loop to do the encryption but how am i to do it meaning the actual encryption itself what is that i check with?Also i think i need more than just the #include <stdio.h> library due to the file functions that i will need or is C having them built in? Also what is that about the program doing all this from DOS?
Create 2 programs with the names encrypt and decrypt that will encrypt and decrypt files respectively.The encryption and decryption will be done through a command line of DOS and the program should be as follows: encrypt file1 file2 key and decrypt file1 file2 key
Where:
file1 is the source file
file2 is the destination file
key is the word with which we encrypt/decrypt file1
So when the user executes the command encrypt f1 f2 sunnyday the program will create a file with the name f2 which will have the contents of f1 encrypted with the key sunnyday.When the user executes the command decrypt f1 f2 sunnyday the program will create a file with the name f2 which will have the contents of f1 decrypted with the key sunnyday.
If the user gives a wrong key the program will continue to decrypt file1 but since the key is wrong the results will be unexpected.Finally the program must print the corresponding error messages in case of errors for example (There is no file 1).The program is expected to work corectly with not only plain text files but executable (exe) files etc.Also The program must be fully commented.
Note: The way the encryption will work is yours to choose but it is recommended that you encrypt every letter of the file with every letter of the key with the (start to finish and begin) technique meaning that if the key has 8 letters then the first leeter of the file will be encrypted with the first letter of the key, the second letter of the file with the second of the key, ..., the ninth letter of the source file with the first letter of the key, the tenth letter of the source file with the second letter of the key etc.
View 3 Replies
View Related
Aug 9, 2013
I just want to test AES from openSSL with this 3 modes: with 128,192 and 256 key length but my decrypted text is different from my input and I dont know why. Also, when I pass a huge inputs length (lets say 1024 bytes) my program shows `core dumped`... My input is always the same but it doesnt matter, at least for now. Heres the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/aes.h>
int main(int argc, char **argv){
[Code] .....
View 1 Replies
View Related
Mar 19, 2015
this program on how to make a encryption and decryption program of a txt file
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
[Code].....
View 1 Replies
View Related
Aug 5, 2014
Back again with a random bug that I can't seem to track down. My error is in my main.cpp file. I get a C2248 error on line 54, there I'm doing:
t.makeEmpty(t.root)
I know why, because it's a private member...but it should have access in so far as everything is concerned. I double checked my makeEmpty code and it's good to go so far as I can tell. I can't quite iron out where the disconnect is.
V/R
Brad
main.cpp
#include <iostream>
#include <string>
[Code].....
View 4 Replies
View Related
Oct 29, 2013
We need an AES Encryption/Decryption program in C for college lab (Educational) purpose . So we cannot use any "aes.h" file for this . We need a C program which simulate the purpose of AES
Input : Text (e.g: Anes P.A)
key (e.g:123op)
Output : Cipher Text using AES
I look this functionality done in a website : [URL] ....
Attached Images : AES.jpg (36.4 KB)
View 1 Replies
View Related
Sep 29, 2013
I am having trouble with an assignment. The assignment consists of a basic encryption and decryption program already written for me, I just have to write the encryption function. What we have to get the program to do is enter an integer and a text, and get the program to increment each letter in the text by the integer given. I did this by using a for loop and incrementing each value in the string by the integer.
However, I still can't get it to decrypt and I need the program to work with only a-z letters (if I increment each letter by 3 and I have the letter Z, it should go to Z+3 = C).
I attached the description of the attachment and below are the codes: The first file does not need to be edited.
Code:
/*******************Programming Assignment 1***************/
/****************Caesar's substitution cipher**************/
/*****************YOU MUST NOT EDIT THIS FILE**************/
/****Substitute alphabets in a string using rotation key***/
/****Leave all other characters unchanged******************/
/****Confirm correct encryption by decrypting**************/
[Code] ......
View 1 Replies
View Related
Mar 8, 2013
I just started to work on a project which is 'Body Area Network'.
What I need to do is to take data from body with some sensor nodes and send it to mobile which would further send the data to a remote server, and I need to add some security (encryption/decryption) on the data.
So I want to know how to send data from mobile after encrypting it to the server and then decrypt it back(on server side).
View 6 Replies
View Related
Feb 14, 2012
I have the following function:
Code:
public static void Des(byte[] key, byte[] inBuf, byte[] outBuf) {
if (key.Length != 8 || inBuf.Length != 8 || outBuf.Length != 8) {
throw new Exception("Des: Buffer or key length incorrect.");
}
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
[Code] ....
I do not get the expected output of
Code: { 0x88, 0xBF, 0x0D, 0xB6, 0xD7, 0x0D, 0xEE, 0x56 }
instead I get
Code: { 0xC6, 0x61, 0x8D, 0x63, 0x0B, 0x39, 0x31, 0xB0 } am I doing something wrong?
I've even tried reversing the byte order of the test data, and I don't get the right result. I've tested the same data using C++ with CryptoPP on Linux, and I get the expected result, but I'm porting this code to run on .Net, and this is my main stoppage in the process at the moment.
View 5 Replies
View Related
Jul 14, 2013
while(!in.eof()) {
in >> ch;
char d = int(ch) + 10;
out << d;
[Code] ....
The first while loop would be to encrypt it, and the second would decrypt it, the decrypting is not giving the original content. For example:
in = Hello
encrypt...
decrypt...
out = Hellooo
View 2 Replies
View Related
Mar 1, 2013
so i need to encrypt a txt document using Caesar encryption. however i don't know how to open a txt and shift the keys into a new txt. the program has to ask the user for the number it should shift. Using arrays, if else. i also need to make a menu so i am using switch.
View 4 Replies
View Related
Sep 6, 2014
How to do encrypt and decrypt the text by using md5 algorithm without using the any library? Only implement in c++ program.
View 4 Replies
View Related
Feb 8, 2014
Is it possible to encrypt a folder and put it in a file container. Would I need to store the header key and other stuff my self or do the encryption methods take care of it? I am just getting into file input/output. I am just looking to make a simple console based one.
View 5 Replies
View Related
Jul 22, 2014
I am trying to make a simple program for encrypting a char* with the XOR operator. The code compiles and links perfectly, but I get an Access violation runtime error:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <fstream>
using namespace std;
int main(int argc, char** argv) {
[Code] .....
Text that I am inputting:
My username is memberfunction.
View 9 Replies
View Related
Apr 18, 2014
Write a program to do simple encryption and decryption. Encryption basically means to convert the message into unreadable form. In this assignment, it should be done by replacing each letter of a message with a different letter of the alphabet which is three positions further in the alphabet. Then, all the letters will be reversed. Decryption is the process of converting encrypted message back into its original message. Your program should use the following shifting method.
Note: You must use array.
#include <iostream>
#include <string>
using namespace std;
[Code].....
View 2 Replies
View Related
Apr 12, 2013
I'm very new to MFC & VisualC++. I'm using MSVS2010 Pro. I am trying to write/debug a simple form that saves and restores the content of some edit controls. It seems to work as expected, except the file saves only to the Project Folder, regardless of where I browse and select to save the file.
Code:
void CMFC_FileDialogDlg::OnBnClickedbtnsave() {
this->UpdateData();
CFile f;
//Kinda Correct, Works but still saves in Project Folder
BOOL b_OpenFileDialog = FALSE;//this doesn't act as bool in CFileDialog?
[Code] ....
My only experience is a little simple VB programming in Excel, so any specific examples??? Also, rules seem to change from version to version? I have to "update" a number of undocumented programs.
View 4 Replies
View Related
Jun 4, 2013
I have written a C++ program I have multiple of CSV file used as input, which I open one at a time and close it after extracting data to a output file which is the only file.
I run getline(inFile,line);
outFile << line << endl;
I run this code, and only part of it is goes to the output file I got, also have spacing randomly to specific file and inconsistent
But when I slower the code, like system("Pause") in the loop, I can get extract what I want perfectly....
Is my program running to fast, why getline would be skipping part of what things I want?
View 11 Replies
View Related
Aug 29, 2014
One of my class assignments is to create a program that receive a .txt file containing a students name and their grades as follows:
John K. 99, 87, 57, 89, 90, 95
Amanda B. Jones 100, 88, 76, 99, 86, 92
etc..
The number of students is unknown until run time. You have to take those grades and average them weighing the first (4) at 10% a piece and the last (2) at 30% each.
Then return an output file with the students name and their letter grade A,B,C,D,F based on their computed score. In addition, on screen it needs to display the average scores for each Q1, Q2, etc. as well as the minimum and maximum for each test on the screen. I am having a hard time in assigning the scores to a variable so that they can then be computed as an average and then used to determine a letter grade. I have begun to write the code and am a bit stuck..here's what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
[Code]....
View 2 Replies
View Related
Nov 24, 2013
I have this code for a computer project... (store management) but the character strings are not copied on text file..
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class Store {
public:
char *item_name[5];
store()
[Code] .....
Now when i run the program, it gives a error :::
ERROR
address 0x0
How can i write these strings to the text file?
View 2 Replies
View Related
Mar 15, 2013
The Objective Of This Program Is To Create A File To Write Text And Read Back The File Content. To Do That I Have Made Two Function writeFile() To Write And readFile() To Read.The readFile() function works just fine but writeFile() doesn't.
How writeFile() function Works? when writeFile() function Execute It Takes Characters User Type And When Hit Enter(ASC|| 10) It Ask "More?(Y/N)" That Means What User Want? Want To Go Next Line Or End Input?
If "Y" Than Inputs Are Taken From Next Line Else Input Ends.
But The Problem Is When Program Encounters ch==10 It Shows "More?(Y/N)" And Takes Input In cmd variable.If cmd=='Y' I Mean More From Next Line Than It Should Execute Scanf Again To Take ch I Mean User Input.But Its Not!!! Its Always Showing "More?(Y/N)" Again And Again Like A Loop.
Code:
#include <stdio.h>
void writeFile(void);
void readFile(void);
int main(){
[Code].....
View 5 Replies
View Related
Feb 12, 2013
I'm writing a program that stores records into a file and then these records can be printed out. A last name, first name, and score is stored to be exactly 36 characters long (using leading spaces to pad) making it easier to retrieve specific records. For example, three records stored in the file would like like this: (the underscores are simply to illustrate the distance, they are not in the file itself)
_______lastname_______firstname__90__________lname __________fname_100___________last___________first __60
When printed out, the names are formatted as follows:
lastname, firstname: 90
lname, fname: 100
last, first: 60
However, when I print them out this is what I get:
lastname, firstname: 90
lname, fname: 100$
last, first: 60H
For some reason, for any record after the first, an extra character is added to the end. These characters are not in the file, so I was thinking that the array for some reason wasn't being filled completely, (the array is initialized to size 36 and 36 characters are read from the file using fread) so it was printing out a random character assigned to the 36th array position. Except the character never changes, (always a $ for record 2, H for record 3, l for record 4 if i remember) and I've tried reducing the array size or the number of character read and it's the string that gets altered, the random character always remains. I figure the problem must be in the print_records function (appending seems to work no problem). Anyway here is my print records and appending records code.
Code: /*
- Prints a single record stored in the file pointed to by ifp.
*/
void print_record(FILE *ifp, int record) {
[Code]......
View 6 Replies
View Related
Jan 19, 2014
I have almost a hundred names in a text file that I want to convert to email addresses and save to another file. I seem to have it working, but it doesn't print the full names in the email prefix. The output I'm looking for is Doe_John@livebrandm, but I'm only getting D_J@livebrandm. I'm not sure what I should specifically be reading up on that applies to this directly.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fpin=fopen("namesIN.txt", "r");
FILE *fpout=fopen("emailOUT.txt", "a");
char first[20],last[20],inbuff[1500];
[Code]...
View 9 Replies
View Related
Feb 6, 2014
I am writing a simple file/text parser to read a config file for some code I am working on. It's dead simple and not particularly smart but it should get the job done. The code reads a config file:
Code:
readlength=2500000
start=0
finish=25000000
cutoff=20000
samplingfreq=250000
poles=10
filterpadding=500
}
[code]....
Here is where it gets wierd. You'll notice that there is an unused variable (filepath) in the config struct. This variable is not referenced or used anywhere in the code, ever. Yet if I comment out the declaration of char filepath[1024], the code segfaults partway through the read_config() function.
My best guess is that there is a buffer overflow elsewhere and it just so happens that the memory allocated for filepath happened to be there to catch it up until now, but I can't work out where it might be happening. With the declaration commented out, the read_config() function gets as far as reading the "padding" variable before it crashes. Yet when the declaration is there, then all the variabled are read correctly and everything seems to work.
View 10 Replies
View Related