C/C++ :: How To Put A Line Of Text File Into Array For Encryption (AES)

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


ADVERTISEMENT

C++ :: Read Line By Line From Text File To String

Jul 5, 2013

I have a text file (test.txt) with the following data:

01,05,25,20130728
01,06,25,20130728
01,07,25,20130728
01,08,25,20130728
01,05,25,20130728
01,05,25,20130728
01,05,45,20130728
01,05,65,20130728
01,05,85,20130728
01,05,35,20130728
01,05,25,20130728
01,05,35,20130728

I want to read this to one string called line. So far I have this code:

string line;
ifstream myfile ("/home/Test.txt");
if (myfile.is_open()) {
while (myfile.good()) {
getline (myfile, line);
for (int a = 0; a <= 335; a++) {
cout <<line.at(a);
} }
myfile.close();
}

so far its only printing the first line and then throwing an instance of 'std::out_of_range'

View 2 Replies View Related

C/C++ :: How To Get Last Line 10 Char In Text File If Last Line Is Null

Aug 24, 2013

I can able to get the last line ten chars but i cant get if the last line is null.

here is my code

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {

[Code] ....

here with i have enclosed my file where i am pick my last ten chars ...

Attached Files : log.txt (4.8 KB)

View 1 Replies View Related

C/C++ :: AES Encryption / Decryption Of Text

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

C++ :: Text Encryption And Decryption Using MD5 Algorithm

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

C++ :: Read From A Txt File And Then Write A New Text File With Sorted Line

Jun 11, 2014

I have a .txt file which I want to read from and then write a new text file, this time with sorted lines. It is easy to sort one value, but what about sorting entire lines based on one value?

I want to sort the lines based on the FIRST value.

Example text file contents:

values;data
5.01 100
2.9 342
2.69 43534
10.1 43
6.8 45324

Output: Text file containing

2.69 43534
2.9 342
5.01 100
6.8 45324
10.1 43

It's easy to do this if there was only 1 number on each line, but I do I sort all the lines based on the first number in each line?

View 2 Replies View Related

C++ :: Delete A Line From A Text File

Jun 7, 2013

How can i delete a line from a file created using a C++ program?Can i get a code sample.

View 1 Replies View Related

C++ ::  How To Delete A Line In A Text File

Jan 29, 2015

The program i wrote can run but did not work. I want to delete a line from the textfile "StaffList.txt" but when i cin the name, for example "Ben". After the program ran finished and i open the textfile, the name "Ben" and the whole line is still inside the textfile! I have created the "temp.txt" file before i run the program.

//information inside the "StaffList.txt"
James S1325685J12580
Peter S8856325K52650
Ben S1025639Z85250
Ken S9052365B74100
Marry S9352654I75320
John S7754852H99630
Jenny S7042525L74530
May S1256985G15960
Betty S1135565K56360
Kyle S9545530A1234100

[code]....

View 2 Replies View Related

C++ :: Possible To Store A New Line At The Above Of Text File

Feb 9, 2014

I need to store the last 3 deposit that I have in my deposit. I have few option but i dont which would be easy

1.Store all deposit to the text file (store always in a new line), and display the last three deposit from the text file.

dep 1 - 60
dep 2 - 40
dep 3 - 100 print 100
dep 4 - 50 print 50
dep 5 - 50 print 50

2. I think this option is more difficult, when it reach deposit 4, to get rid deposit 1

So when i make a deposit 4, the deposit 1 get's ride
dep 2 - 50
dep 3 - 100
dep 4 - 70

Right now i can only display one deposit (last one), then i close the program and run again and i make another deposit it overwrites a new deposit.

My code.
To show sure my deposit that has been made.
double depSave () {
int option;
float dep1,dep2,dep3;// Declare your variables
dep1 = dep2 = dep3 = 0; // Set them all to 0

system ("cls");
string path = "deposit.txt"; // Storing your filename in a string

[Code] ....

Where is says "save deposit" in comment that where it saves to the deposit text file, that going to be output to the depSave function.

View 2 Replies View Related

C++ :: Read Last Line Text File?

Aug 16, 2013

I am making a script to read the latest from a text file. It picks up the line by numbytes in fseek, but the data line may vary and numbytes not be accurate, how can I fix this?

And another problem is that the line has, date, time, value, separated by space, how to read that line and put these 3 information in variable?

#include <stdio.h>
#include <conio.h>
int main() {
FILE *arq;
char Line[100];
char *result;
int tam, i;
// Opens a file for READING TEXT
arq = fopen("temp.txt", "rt");

[code].....

View 19 Replies View Related

C++ :: How To Delete A Line From Text File Using Fstream

Dec 16, 2014

I'm trying to make a simple phonebook app that can show contacts, add, and delete. I'm pretty new to C++ and fstream functions, deleting a line in my bool erase() function?

#include <iostream>
#include <conio.h>
#include <string>

[Code].....

View 6 Replies View Related

C++ :: Sort Text File By First Number Of The Line

Dec 24, 2013

I have a text file like this

0 1 2 C
10 1 2 S
7 1 2 C
11 1 2 S
9 3 43 C
10 3 43 S
1 3 43 C
101 3 43 S

with this code

ifstream in("fout2.txt");
if (in) {
vector<string> lines;
string line;
while (getline(in, line))

[Code] ....

I obtain this result

0 1 2 C
1 3 43 C
10 1 2 S
10 3 43 S
11 1 2 S
101 3 43 S
7 1 2 C
9 3 43 C

but i want a result like this :

0 1 2 C
1 3 43 C
7 1 2 C
9 3 43 C
10 1 2 S
10 3 43 S
11 1 2 S
101 3 43 S

View 3 Replies View Related

C/C++ :: Reading In A Text File With New Line Delimiter?

Feb 23, 2014

I have attached the file that I need to read into a data structure. In the example I am just printing it to the screen. This following code has worked for me before, but now isn't. I have tried in visual studios, and on unix, and neither are running it. I ultimately need it to run on unix.

Example file:

word
book
programming

Here is my function to read in the file.

ifstream file;
string line;
file.open("words.txt");
if(file.is_open()){
while(!file.eof()){
getline(file, line);
cout << line <<endl;
}
}
file.close();

View 7 Replies View Related

C++ :: Reading Text File - Extra Line

Feb 9, 2012

Why this code outputs 7 lines (the last line twice) while the file contains 6 lines?

cout << "read msgfile
";
ifstream msgfile ("script1.msg");
while (msgfile.good()) //if not at end of file, continue reading {
// load vector with deffile
msgfile >> line;
vectormsgfile.push_back (line);
cout << line << "
";
}
msgfile.close();

View 2 Replies View Related

C :: Open New Text File With First Letter Of Line On A Certain Directory

May 23, 2013

I'm reading from stdin a line. With that line, I should open a new textfile with the first letter of that line on a certain directory. My code is the following :

Code:

int main() {
char line[BUFSIZ];
FILE *ptr_file;
int x;
while(fgets(line,BUFSIZ,stdin) != NULL){

[Code] ....

char caminho[] is the directory in which I want to create the text file and chave will be the first letter of the line in stdin.

How am I supposed to use strcat to get these two together in a string to then use ptr_file =fopen(caminho, "w");

View 3 Replies View Related

C++ :: Read Text File To Stringstream But Keep Line Feed

Jun 6, 2013

I build this function in my C++ code. I run the on a UNIX box, build HTML file to use in Windows.

In HTML file building code, I have only a string variable hold the contents of this text file (from unix) & add it into HTML file.

The issue is that when I view the HTML file on windows, it shows all the lines in the text file as one line. I think it lost the CRLF.

My question is when I add lines from text file (reading one line at a time) in UNIX, how do I maintain CRLF ( ) in the stringstream variable so that it will display on HTML in Windows properly, all the lines as it is in unix.

I am aware UNIX uses for line end.

string TextFileToString(string filename) {
string line;
stringstream dosString;
ifstream inFile;

[Code] ......

View 4 Replies View Related

C++ :: Use Find Function To Search For A Line In Text File

Oct 28, 2013

I'm trying to make a program that will search for a line in a text file using a non default delimitor at the start of the line. An example line in the text file would be as follows:

F Mary Smyth, 19, United Kingdom

I have been able to use the find function to search for and return the 'F' character but would like it to then display the whole corresponding line. Is this possible with the find function?

ifstream readFromFile("data.txt");
string Destinations[1] = {"F "};
string data;
while(!readFromFile.eof()){
getline(readFromFile,data);

[code]...

View 2 Replies View Related

C++ :: Removing All White Space From Line Of Text File?

Jun 30, 2014

this is the code I tried in my code block 10.05.....tried code for removing all white space from a line of a txt file. this is my code it runs but i cant get the result i need.

#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>

[Code].....

View 9 Replies View Related

C++ :: Reading Group Of Numbers Per Line In Text File

Mar 27, 2013

I am working on a project for school that has us read in a text file that contains 8 lines of SSN and grades. I am not sure how to go about reading in the lines and differentiate between the SSN and grades in the calculations.

View 1 Replies View Related

C++ :: Reading From A Text File - ID And GPA In Same Line Separated By Comma

Nov 9, 2013

I tried to read in a file that contain studentId(8 integer long) and GPA in the same line separated by a comma, but I couldn't. Example:

145453565, 4.0
34344443, 3.9
23454345, 3.4
12345678, 3.4

void studentRecord::loading(string filename) {
ifstream infile;
int studentId;
double GPA;

[Code] ....

View 3 Replies View Related

C/C++ :: Delete Specific Line In Text File Using Program?

Feb 6, 2014

Some codes to delete a text in a specific line in a text file.

Example:
This is line 1
This is line 2
this is line 3

Removing line 2,

This is line 1

This is line 3
//////////////////

View 2 Replies View Related

C++ :: Read Text File - First Line Has Extra Char

May 21, 2012

When I read a text file. I'm reading a list of strings in text file, with one string per line. The first line has extra characters in the string, the rest of the lines read are fine, and I can't understand where the extra characters come from. The file format is this...

A
AA
AAN
AAP
AAPL
AAWW
AAXJ
....
...

Code:
std::vector<std::string> strSymbolList;
std::string s = "";
std::ifstream infile( m_strFileSymbols );
while( std::getline(infile, s) ) {
strSymbolList.push_back(s);
}
infile.close();

View 3 Replies View Related

C :: Read Txt File And Print Contents Numbering Each New Line Of Text?

Apr 25, 2013

I have written the following code but i am stuck. Write a program that will prompt the user for a file name and open that file for reading. Print out all the information in the file, numbering each new line of text.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
int main()
{
char line[81], filename[21], c;
int i = 1;
FILE *inFile;

[code]....

View 3 Replies View Related

C++ :: Search By Word In Text File And Print Out Whole Line On Screen

Apr 7, 2013

I have a text file where in each line is 3 words and 2 int type numbers. I'm doing search by word and I want to print out to the screen the whole line where that word was found (the words is repeated in some lines). My search looks like this:

Code:
#include<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>
#include <vector>
using namespace std;
int main(){
vector <string> words;
string str, paieska;

[Code] .....

How to print line(s) where I found that word?

View 9 Replies View Related

C++ :: Program That Reads Text From A File And Outputs Each Line To The Screen - I/O Streams

Jun 15, 2013

I seem to be missing a concept or 2 here ... I am tasked with writing a program that reads text from a file and outputs each line to the screen as well as to another file PRECEDED by a line number ...

In addition, I have to Print the line number at the start of the line and right-adjusted in a field of 3 spaces ...

Follow the line number with a colon then 1 space, then the text of the line.

Another kicker, is I have to grab the data 1 character at a time and write code to ignore leading blanks on each line.

Here is what I have so far:

#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cctype>
using namespace std;
int main() {
char next;
int count = 0;

[Code] ....

View 7 Replies View Related

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 View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved