| | |
Question, basic encrpytion?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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 beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






