-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
17,499 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
# DInnDemo2 | ||
# DemoOFdinn | ||
A simple demo for dinn | ||
|
||
1.仅支持16 * 16的图片,没有保护程序,识别非规范图片会崩溃 | ||
|
||
2.qt文件,生成可执行程序后,需要将weights文件夹中的txt文件复制到程序目录下 | ||
|
||
3.提供测试图片,在testpic文件夹中 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "mainwindow.h" | ||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
MainWindow w; | ||
w.show(); | ||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#include "mainwindow.h" | ||
#include "ui_mainwindow.h" | ||
#include <QDebug> | ||
#include <QPalette> | ||
#include <QString> | ||
#include "qtnn.h" | ||
|
||
MainWindow::MainWindow(QWidget *parent) | ||
: QMainWindow(parent) | ||
, ui(new Ui::MainWindow) | ||
{ | ||
ui->setupUi(this); | ||
this->setWindowIcon(QIcon("../untitled/Image/icon.jpg")); | ||
this->setWindowTitle(("李鹏博")); | ||
//设置按钮颜色 | ||
// QPalette pal = (ui->openAction)->palette(); | ||
// pal.setColor(QPalette::ButtonText, Qt::red); | ||
// al.setColor(QPalette::Button, Qt::green); | ||
// ui->openAction->setPalette(pal); | ||
|
||
|
||
|
||
this->m_image=new int[256]; | ||
TFheGateBootstrappingParameterSet *params = our_default_gate_bootstrapping_parameters(80); | ||
this->m_paras=params->in_out_params; | ||
this->m_secret = new_random_gate_bootstrapping_secret_keyset(params); | ||
this->enc_m_image = new_LweSample_array(256, this->m_paras); | ||
this->enc_m_scores = new_LweSample_array(10 ,this->m_paras); | ||
} | ||
|
||
MainWindow::~MainWindow() | ||
{ | ||
delete ui; | ||
} | ||
|
||
|
||
|
||
void MainWindow::on_openAction_clicked() | ||
{ | ||
//读取图片的路径 | ||
QString filename; | ||
filename = QFileDialog::getOpenFileName(this, tr("Select image:"), | ||
"D:\\Documents\\Pictures", tr("Images (*.png *.bmp *.jpg *.gif)")); | ||
if (filename.isEmpty()) { | ||
return ; | ||
} | ||
//读取的图片 | ||
QImage image; | ||
if (!image.load(filename)) { | ||
QMessageBox::information(this, tr("Error"), tr("Open file error")); | ||
return ; | ||
} | ||
|
||
setWindowTitle(QFileInfo(filename).fileName() + tr(" - imageViewer")); | ||
|
||
QImage imagegry = image.convertToFormat(QImage::Format_Grayscale8); | ||
|
||
|
||
QPixmap pixmap = QPixmap::fromImage(imagegry); // | ||
qDebug() << "filname: " << pixmap; | ||
|
||
ui->imageLabel->setPixmap(pixmap); | ||
ui->imageLabel->resize(pixmap.size()); | ||
|
||
ui->imageLabel->setPixmap(pixmap.scaled(ui->imageLabel->size(), Qt::IgnoreAspectRatio , Qt::SmoothTransformation)); | ||
|
||
unsigned char *pData=imagegry.bits(); | ||
for(int i=0;i<16*16;i+=1) | ||
{ | ||
if (pData[i]<128){ | ||
pData[i]=0; | ||
m_image[i]=-1; | ||
} | ||
else{ | ||
pData[i]=1; | ||
m_image[i]=1; | ||
} | ||
if (i%16 == 0) | ||
cout<<endl; | ||
cout<<int((m_image[i]))<<" "; | ||
} | ||
|
||
} | ||
|
||
void MainWindow::on_changeAction_clicked() | ||
{ | ||
//int image_class; | ||
net(this->enc_m_image,this->enc_m_scores,this->m_secret->cloud.bkFFT,this->m_paras); | ||
//ui->dataEdit->setText(QString::number(image_class)); | ||
|
||
} | ||
|
||
void MainWindow::on_encryptAction_clicked() | ||
{ | ||
encrypt(this->m_image,this->enc_m_image,this->m_secret,this->m_paras); | ||
QImage imagegry_enc = QImage(16, 16, QImage::Format_Grayscale8); | ||
int count =0; | ||
int grey=0; | ||
for(int x = 0; x<imagegry_enc.width(); x++){ | ||
for(int y = 0; y<imagegry_enc.height(); y++){ | ||
grey = int(this->enc_m_image[count].b/(2^32)*255); | ||
imagegry_enc.setPixel(x,y,grey); | ||
count+=1; | ||
} | ||
} | ||
|
||
|
||
QPixmap pixmap = QPixmap::fromImage(imagegry_enc); // | ||
qDebug() << "filname: " << pixmap; | ||
|
||
ui->imageLabel_2->setPixmap(pixmap); | ||
ui->imageLabel_2->resize(pixmap.size()); | ||
|
||
ui->imageLabel_2->setPixmap(pixmap.scaled(ui->imageLabel_2->size(), Qt::IgnoreAspectRatio , Qt::SmoothTransformation)); | ||
|
||
|
||
|
||
} | ||
void MainWindow::on_decryptAction_clicked() | ||
{ | ||
int image_class; | ||
image_class=decrypt(this->enc_m_scores,this->m_secret); | ||
ui->dataEdit->setText(QString::number(image_class)); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef MAINWINDOW_H | ||
#define MAINWINDOW_H | ||
|
||
#include <QMainWindow> | ||
#include <QFileDialog> | ||
#include <QImage> | ||
#include <QPixmap> | ||
#include <QFileInfo> | ||
#include <QMessageBox> | ||
#include "qtnn.h" | ||
|
||
QT_BEGIN_NAMESPACE | ||
namespace Ui { class MainWindow; } | ||
QT_END_NAMESPACE | ||
|
||
class MainWindow : public QMainWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
MainWindow(QWidget *parent = nullptr); | ||
~MainWindow(); | ||
|
||
private slots: | ||
void on_openAction_clicked(); | ||
|
||
void on_changeAction_clicked(); | ||
|
||
void on_encryptAction_clicked(); | ||
|
||
void on_decryptAction_clicked(); | ||
private: | ||
Ui::MainWindow *ui; | ||
int * m_image; //上传的图片 | ||
// struct LweSample enc_m_image[255]; //加密后的图片 它是STruct ,密文成员 直接enc_m_image[i].b | ||
// struct TFheGateBootstrappingSecretKeySet * m_secret; //生成的私钥 | ||
// struct LweSample enc_m_scores[255]; | ||
struct LweSample * enc_m_image; //加密后的图片 它是STruct ,密文成员 直接enc_m_image[i].b | ||
struct TFheGateBootstrappingSecretKeySet * m_secret; //生成的私钥 | ||
struct LweSample * enc_m_scores; | ||
const struct LweParams * m_paras; | ||
|
||
}; | ||
#endif // MAINWINDOW_H |
Oops, something went wrong.