C++ - String encryption


SUBMITTED BY: Guest

DATE: Nov. 30, 2014, 4:14 p.m.

FORMAT: C++

SIZE: 993 Bytes

HITS: 11067

  1. //To be compiled using VS 2013
  2. #include <iostream>
  3. #include <string>
  4. #include <conio.h>
  5. #ifndef MOVE_C
  6. #define MOVE_C 3
  7. #endif
  8. using namespace std;
  9. void rol(int tablica[], int wielkosc)
  10. {
  11. for (int i = 0; i < wielkosc; i++)
  12. {
  13. tablica[i] = (tablica[i] << MOVE_C) | (tablica[i] >> (sizeof(int) * CHAR_BIT - MOVE_C));
  14. }
  15. }
  16. int main()
  17. {
  18. string kappa = "";
  19. int dlugosc = 0;
  20. cout << "Podaj tekst do zaszyfrowania: ";
  21. getline(cin, kappa);
  22. dlugosc = kappa.size();
  23. int* asciitab = new int[dlugosc];
  24. for (int i = 0; i < dlugosc; i++)
  25. {
  26. asciitab[i] = static_cast<int>(kappa[i]);
  27. }
  28. rol(asciitab, dlugosc);
  29. for (int j = 0; j < dlugosc; j++)
  30. {
  31. asciitab[j] = ~asciitab[j];
  32. }
  33. cout << "Zaszyfrowana postac: ";
  34. for (int k = 0; k < dlugosc; k++)
  35. {
  36. cout << asciitab[k] << " ";
  37. }
  38. _getch();
  39. delete[] asciitab;
  40. return 0;
  41. }

comments powered by Disqus