#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
QString MainWindow::toUpperAndLower(QString src)
{
for(int i = 0; i < src.count(); i++) {
QChar curC = src.at(i);
if(curC.isUpper()) {
curC = curC.toLower();
} else if(curC.isLower()){
curC = curC.toUpper();
}
src[i] = curC;
}
return src;
}
QString MainWindow::toXOREncryptUncrypt(QString src, const QChar key)
{
for(int i = 0; i < src.count(); i++) {
src[i] = src.at(i).toLatin1() ^ key.toLatin1();
}
return src;
}
void MainWindow::on_pushButton_a_clicked()
{
QByteArray text = ui->lineEdit_a->text().toLocal8Bit();
QByteArray by = text.toBase64();
ui->label_a->setText(by);
ui->lineEdit_j->setText(by);
}
void MainWindow::on_pushButton_j_clicked()
{
QByteArray text = ui->lineEdit_j->text().toLocal8Bit();
QByteArray by = text.fromBase64(text);
QString str = QString::fromLocal8Bit(by);
ui->label_j->setText(str);
}
void MainWindow::on_pushButton_a_2_clicked()
{
QByteArray text = ui->lineEdit_a_2->text().toLocal8Bit();
QByteArray by = text.toBase64();
QString str = QString(by);
str = toUpperAndLower(str); // 加密
ui->label_a_2->setText(str);
ui->lineEdit_j_2->setText(str);
}
void MainWindow::on_pushButton_j_2_clicked()
{
QString str = toUpperAndLower(ui->lineEdit_j_2->text()); //解密
QByteArray text = str.toLocal8Bit();
QByteArray by = text.fromBase64(text);
str = QString::fromLocal8Bit(by);
ui->label_j_2->setText(str);
}
void MainWindow::on_pushButton_a_3_clicked()
{
QByteArray text = ui->lineEdit_a_3->text().toLocal8Bit();
QByteArray by = text.toBase64();
QString str = QString(by);
str = toXOREncryptUncrypt(str, 'g'); // 加密 --- 注意:(这里的key是可以指定为任意字符的,相应的,解密也要同意字符才行)
ui->label_a_3->setText(str);
ui->lineEdit_j_3->setText(str);
}
void MainWindow::on_pushButton_j_3_clicked()
{
QString str = toXOREncryptUncrypt(ui->lineEdit_j_3->text(), 'g'); //解密
QByteArray text = str.toLocal8Bit();
QByteArray by = text.fromBase64(text);
str = QString::fromLocal8Bit(by);
ui->label_j_3->setText(str);
到此这篇密码的加密与解密的方式(密码的加密与解密的方式不包括)的文章就 介绍到这了,更多相关内容请继续浏览下面的相关 推荐文章,希望大家都能在 编程的领域有一番成就!版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/haskellbc/38192.html