Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. void encode(string key, string file)
  8. {
  9. ifstream cin(file);
  10. ofstream cout("DC.txt");
  11. char c;
  12. int i = 0;
  13. while (!cin.eof())
  14. {
  15. c = cin.get();
  16. if (c != -1)
  17. {
  18. int tmp = c, help = key[i % key.length()];
  19. cout << char(tmp ^ help);
  20. }
  21. i++;
  22. }
  23. cin.close();
  24. cout.close();
  25. }
  26. void code(string key, string file)
  27. {
  28. ifstream cin(file);
  29. ofstream cout("CD.txt");
  30. char c;
  31. int i = 0;
  32. while (!cin.eof())
  33. {
  34. c = cin.get();
  35. if (c != -1)
  36. {
  37. int tmp = c, help = key[i % key.length()];
  38. cout << char(tmp ^ help);
  39. }
  40. i++;
  41. }
  42. cin.close();
  43. cout.close();
  44. }
  45.  
  46. int main()
  47. {
  48. //setlocale(LC_ALL, "Russian");
  49. //char q = 'я'; cout << int(q);
  50. cout << "Sorry, but you can use this programm, if your code/encode file doesn't have Russian symbols.\nChoose the programm mode:\nWrite 1 if you need to encode file. Write 2 if you need to code file: ";
  51. int choice;
  52. cin >> choice;
  53. if (choice == 1)
  54. {
  55. string file, key;
  56. cout << "Write the name(with file extension) of file, which you need to encode: ";
  57. cin >> file;
  58. cout << "Write the key of code: ";
  59. cin >> key;
  60. encode(key, file);
  61. cout << "Decode file is DC.txt\n";
  62. }
  63. else
  64. {
  65. if (choice == 2)
  66. {
  67. string file, key;
  68. cout << "Write the name(with file extension) of file, which you need to code: ";
  69. cin >> file;
  70. cout << "Write the key of code: ";
  71. cin >> key;
  72. encode(key, file);
  73. cout << "Code file is CD.txt\n";
  74. }
  75. }
  76. cout << "My English is very well!!!";
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement