| | |
Question, basic encrpytion?
![]() |
i am trying to write a program that takes information from a file and reads it and then does some kind of encryption, simple as adding one to it
I have it reading the file,
but how would i go about readings the characters as int's
and then adding a number to them?
example:
"Hi blah blah" = 234234 345634634 345345345 345345345
I want this to be stored in their number form + some number.
I have it reading the file,
but how would i go about readings the characters as int's
and then adding a number to them?
example:
"Hi blah blah" = 234234 345634634 345345345 345345345
I want this to be stored in their number form + some number.
char data type is a small int whose value is between -126 and 127. So do do what you want just loop through the array and add 1 to the char value.
C++ Syntax (Toggle Plain Text)
char str[] = "Hi blah blah"; // add 1 to the first character, syntax is idental to int ++str[0];
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
after reading the string from a text file to the encryption like I posted earlier. Do you know how to read files ? In c++ use the ifstream class to read a text file. Here is an example of how to read/write text files.
Last edited by Ancient Dragon; Jun 6th, 2007 at 11:53 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
This is the code i have so far, which only displays "file.txt" and displays it.
p.s. is there a way to tab in this chat box?
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<fstream> using namespace std; const int SIZEMAX = 81; void read(fstream &); int main() { fstream dataFile; dataFile.open("file.txt", ios::in); if(dataFile.fail()) { cout << "The file does not exist. Please check your file." << endl; return 0; } read(dataFile); dataFile.close(); cout << endl << "Done" << endl; return 0; } void read(fstream &file) { char line[SIZEMAX]; while( file >> line) { cout << line << endl; } }
Last edited by Ancient Dragon; Jun 7th, 2007 at 7:09 am. Reason: replaced quote tags with code tags
Well, this isn't really encryption, but I can't really figure out what you're trying to do to obtain the numbers. This just prints out the ASCII value for each character by casting to int.
This code is fairly clear; it is trivial to modify it to fit into your read() function.
C++ Syntax (Toggle Plain Text)
int i = 0; while(myString[i]) { std::cout << static_cast<int>(myString[i]) << " "; i++; } std::cout << std::endl;
"Technological progress is like an axe in the hands of a pathological criminal."
![]() |
Similar Threads
- PThreads: question on basic problem (or POSIX Threads) (C)
- Getting started in programming (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: Where to get C++ GUI prgramming tutorials?
- Next Thread: My solution to 2 beginner questions
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes code coding compaitibility compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error factorial file floatingpoint forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix maze memory multiple net news node oop output parameter payment pointer practice problem program programming project projectassignmenthelp protection python random rank read recursion reference rpg skills string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






