mainwindow.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include <QCryptographicHash>
  4. #include <QMainWindow>
  5. QT_BEGIN_NAMESPACE
  6. namespace Ui { class MainWindow; }
  7. QT_END_NAMESPACE
  8. class MainWindow : public QMainWindow
  9. {
  10. Q_OBJECT
  11. public:
  12. MainWindow(QWidget *parent = nullptr);
  13. ~MainWindow();
  14. private slots:
  15. void on_pushButton_clicked();
  16. private:
  17. Ui::MainWindow *ui;
  18. QString hashString(const QString &str) {
  19. QString strippedStr = str;
  20. strippedStr.remove(QChar('-'));
  21. QByteArray hashData = QCryptographicHash::hash(strippedStr.toUtf8(), QCryptographicHash::Sha256);
  22. QString hashedStr = QString::fromLatin1(hashData.toHex());
  23. return hashedStr;
  24. }
  25. QString caesarCipher(const QString &text, int shift) {
  26. QString result;
  27. const int alphabetSize = 26;
  28. const int digitSize = 10;
  29. for (const QChar &ch : text) {
  30. if (ch.isLetter()) {
  31. QChar base = ch.isLower() ? 'a' : 'A';
  32. result.append(QChar((ch.toLatin1() - base.toLatin1() + shift + alphabetSize) % alphabetSize + base.toLatin1()));
  33. } else if (ch.isDigit()) {
  34. result.append(QChar((ch.toLatin1() - '0' + shift + digitSize) % digitSize + '0'));
  35. } else {
  36. result.append(ch);
  37. }
  38. }
  39. return result;
  40. }
  41. };
  42. #endif // MAINWINDOW_H