Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include<cctype>
  5. #include<time.h>
  6. #define _CRT_SECURE_NO_WARNINGS
  7. #pragma warning(disable: 4996)
  8. using namespace std;
  9. int main() {
  10. srand(time(0));
  11. int a = 20;
  12. FILE* fp;
  13. fp = fopen("test.txt", "w+");
  14. fprintf(fp, "This is line 1\n");
  15. fclose(fp);
  16.  
  17. FILE* fp1;
  18. fp1 = fopen("test1.txt", "w+");
  19. fclose(fp1);
  20. fstream test;
  21.  
  22. test.open("test.txt", ios::in);
  23. if (test.is_open()) {
  24. string text;
  25. string code;
  26. while (getline(test, text))
  27. {
  28. int *numbers = new int[text.length()];
  29. for (int i = 0; i < text.length(); i++)
  30. {
  31. if (isblank(text[i]) != 0)
  32. {
  33. cout << text[i];
  34. code += " ";
  35. }
  36. else
  37. {
  38. int x = (rand() % 30);
  39. numbers[i] = x;
  40. char t = text[i] + x;
  41. cout << t;
  42. code += t;
  43. }
  44. }
  45. cout << endl;
  46. fstream test1;
  47. test1.open("test1.txt", ios::out);
  48. if (test1.is_open())
  49. {
  50. test1 << code;
  51. test1.close();
  52. }
  53. test1.open("test1.txt", ios::in);
  54. if (test1.is_open()) {
  55. string text1;
  56. while (getline(test1, text1)) {
  57. for (int i = 0; i < text1.length(); i++)
  58. {
  59. char t1 = text1[i] - numbers[i];
  60. if (t1 == 'S')
  61. cout << " ";
  62. else
  63. cout << t1;
  64. }
  65. }
  66. test1.close();
  67. }
  68.  
  69. }
  70. test.close();
  71. }
  72.  
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement