Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. char information(char k) { //A function that receives as a character input, the function must calculate and return the encrypted //character to the resulting character
  6. int x = 0;
  7. if (k == 32) //space
  8. k = 32;
  9. if (k >= 48 && k <= 57) { //0-9
  10. x = k - 48;
  11. k = 57 - x;
  12. }
  13. else if (k >= 65 && k <= 90) { //A-Z
  14. x = k - 65;
  15. k = 90 - x;
  16. }
  17. else if (k >= 97 && k <= 122) { //a-z
  18. x = k - 97;
  19. k = 122 - x;
  20. }
  21. return k;
  22. }
  23. int main() {
  24. char k ;
  25. ifstream data("data.txt"); //open file
  26. ofstream encoding("encoding.txt"); //open the file
  27. if (!data||!encoding) { //checking the file
  28. cout << "can not open the file" << endl;
  29. return -1;
  30. }
  31. k = data.get();
  32. while (!data.eof()) { //do it until finish reading data text
  33. encoding << information(k);;
  34. k=data.get();
  35. }
  36. data.close();
  37. encoding.close();
  38. system("pause");
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement