Guest User

Untitled

a guest
May 19th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. GOT IT NIGGA
  2.  
  3. //Zachary Mitchell
  4. //Period 5
  5. //C++ Class Project
  6. #include <string> // so i can declare strings
  7. #include <sstream> // for my stringstreams<3
  8. #include <iostream> // for cout/cin
  9. #include <fstream>
  10. using namespace std; // so i dont have to use the obnoxious std:: on every other line
  11.  
  12. //global variables
  13. string stringHolder = "";
  14. string arr[3];
  15. double arr2[3];
  16. double option;
  17. char charHolder[256];
  18. int count;
  19.  
  20. //my class
  21. class Ascii {
  22.  
  23. public:
  24.  
  25. //outputs the options
  26. void output() {
  27. cout<< "1Encrypt-2Decrypt-3Both" << endl;
  28. cin >> option;
  29. cout << endl << "Enter String(Dont make it longer than four words):";
  30. cin.ignore();
  31. getline(cin,stringHolder);
  32. }
  33.  
  34. //breaks string into words
  35. void stringBreaker() {
  36. int i = 0;
  37. stringstream ssin(stringHolder);
  38. while (ssin.good() && i < 4){
  39. ssin >> arr[i];
  40. ++i;
  41. }
  42. for(i = 0; i < 4; i++) {
  43. cout << arr[i] << endl;
  44. }
  45. }
  46.  
  47. //will output both encrypted and decrypted versions
  48. string all() {
  49. stringBreaker();
  50. return (arr[0], arr[1], arr[2], arr[3]);
  51. }
  52.  
  53. //encrypts to ascii
  54. void encrypt() {
  55. int count2 = -1;
  56. cout << "Before String Breaker:"<<endl;
  57. stringBreaker();
  58. cout <<"Before Char Breaker:"<< endl;
  59. charBreaker();
  60. while(count2 <= 256) {
  61. count2++;
  62. if(charHolder[count2] == 'a') {
  63. charHolder[count2] == '1';
  64. }
  65. cout << " " << charHolder[count2];
  66. }
  67. }
  68.  
  69. //decrypts from ascii
  70. void decrypt() {
  71. stringBreaker();
  72. }
  73.  
  74. //breaks string into char[]
  75. void charBreaker() {
  76. int count=stringHolder.size();
  77. for (int a=0;a<count;a++)
  78. {
  79. charHolder[a]=stringHolder[a];
  80. }
  81. }
  82.  
  83. //saves data to .txt
  84. void saveData() {
  85. ofstream myfile;
  86. myfile.open ("4 word string.txt");
  87. myfile << "Pre encyrption: " << arr[0] << endl << arr[1] << endl << arr[2] << endl << arr[3] << endl << endl << endl << endl;
  88. myfile << "After encyrption: " << arr2[0] << endl << arr2[1] << endl << arr[22] << endl << arr2[3];
  89. myfile.close();
  90. }
  91. private:
  92. //you dont have privates
  93. };
  94.  
  95. int main() {
  96.  
  97. //local variables
  98. string output;
  99. Ascii ascii;
  100.  
  101. //output
  102. ascii.output();
  103.  
  104. //checking option to see what to do
  105. if (option == 1) {
  106. ascii.encrypt();
  107. } else if(option == 2) {
  108. ascii.decrypt();
  109. } else {
  110. ascii.all();
  111. }
  112.  
  113. //pause then, then save, then close
  114. system("Pause");
  115. ascii.saveData();
  116. return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment