Question, basic encrpytion?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2007
Posts: 5
Reputation: MrMan2787 is an unknown quantity at this point 
Solved Threads: 0
MrMan2787's Avatar
MrMan2787 MrMan2787 is offline Offline
Newbie Poster

Question, basic encrpytion?

 
0
  #1
Jun 6th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Question, basic encrpytion?

 
0
  #2
Jun 6th, 2007
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.
  1. char str[] = "Hi blah blah";
  2. // add 1 to the first character, syntax is idental to int
  3. ++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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 5
Reputation: MrMan2787 is an unknown quantity at this point 
Solved Threads: 0
MrMan2787's Avatar
MrMan2787 MrMan2787 is offline Offline
Newbie Poster

Re: Question, basic encrpytion?

 
0
  #3
Jun 6th, 2007
Thanx, hmm but i still have one problem...

I need to read the text from a file.

So is there a way to read from the file and
then put that data into an array?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Question, basic encrpytion?

 
0
  #4
Jun 6th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 5
Reputation: MrMan2787 is an unknown quantity at this point 
Solved Threads: 0
MrMan2787's Avatar
MrMan2787 MrMan2787 is offline Offline
Newbie Poster

Re: Question, basic encrpytion?

 
0
  #5
Jun 6th, 2007
This is the code i have so far, which only displays "file.txt" and displays it.


  1. #include<iostream>
  2. #include<fstream>
  3.  
  4. using namespace std;
  5.  
  6. const int SIZEMAX = 81;
  7.  
  8. void read(fstream &);
  9.  
  10. int main()
  11. {
  12.  
  13. fstream dataFile;
  14.  
  15. dataFile.open("file.txt", ios::in);
  16. if(dataFile.fail())
  17. {
  18. cout << "The file does not exist. Please check your file."
  19. << endl;
  20.  
  21. return 0;
  22. }
  23.  
  24.  
  25. read(dataFile);
  26.  
  27. dataFile.close();
  28. cout << endl << "Done" << endl;
  29.  
  30.  
  31. return 0;
  32.  
  33. }
  34.  
  35.  
  36. void read(fstream &file)
  37. {
  38. char line[SIZEMAX];
  39.  
  40. while( file >> line)
  41. {
  42. cout << line << endl;
  43. }
  44. }
p.s. is there a way to tab in this chat box?
Last edited by Ancient Dragon; Jun 7th, 2007 at 7:09 am. Reason: replaced quote tags with code tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Question, basic encrpytion?

 
0
  #6
Jun 7th, 2007
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.

  1. int i = 0;
  2. while(myString[i]) {
  3. std::cout << static_cast<int>(myString[i]) << " ";
  4. i++;
  5. }
  6. std::cout << std::endl;
This code is fairly clear; it is trivial to modify it to fit into your read() function.
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Question, basic encrpytion?

 
0
  #7
Jun 7th, 2007
at line 42 add another loop to encrypt the line as suggested earlier then output the result to the screen as illustrated by joe.
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC