2016-11-03 50 views
-7

我需要使用C++和XOR加密來加密和解密文件。我需要知道我可以在哪裏爲它製作GUI。C++:密碼學上的迷你項目

有沒有辦法做到這一點(可能通過C + +)?

+0

顯然這個網站的主題。 –

+0

@RicharCritten我應該問哪裏? –

+0

如果您正在尋找某人爲您編寫軟件,那麼您應該詢問一位軟件工程師。如果你正在編寫軟件,那麼你應該通過課程和/或閱讀教學C++書籍來學習C++。 –

回答

0

對於如何加密文件有一個相當簡單的答案。 此腳本使用XOR encryption加密文件。 再次加密文件以解密文件。

#include <iostream> 
#include <fstream> 
#include <string> 

using namespace std; 

void encrypt (string &key,string &data){ 
float percent; 
for (int i = 0;i < data.size();i++){ 
percent = (100*i)/key.size();    //progress of encryption 
data[i] = data.c_str()[i]^key[i%key.size()]; 
if (percent < 100){       
    cout << percent << "%\r";    //outputs percent, \r makes 
}else{          //cout to overwrite the 
    cout<< "100%\r";      //last line. 
} 
} 

} 
int main() 
{ 
string data; 
string key = "This_is_the_key"; 
ifstream in ("File",ios::binary); // this input stream opens the 
            // the file and ... 
data.reserve (1000); 
in >> data;      // ... reads the data in it. 
in.close(); 
encrypt(key,data);     
ofstream out("File",ios::binary);//opens the output stream and ... 
out << data;      //... writes encrypted data to file. 
out.close(); 


return 0; 
} 

這行代碼是在加密情況:

data[i] = data.c_str()[i]^key[i%key.size()]; 

它單獨地加密每個字節。 每個字節進行加密,因爲這種加密 期間更改一個字符:

key[i%key.size()] 

但也有很多的加密方法,例如,你可以加1,每個字節(加密)和減去1從每個字節(解密):

//Encryption 
for (int i = 0;i < data.size();i++){ 
    data[i] = data.c_str()[i]+1; 
} 
//Decryption 
for (int i = 0;i < data.size();i++){ 
    data[i] = data.c_str()[i]-1; 
} 

我認爲這是沒有什麼用處,因爲它是快速的顯示進度。

如果你真的想做一個GUI,我會推薦Visual Studio。

希望有幫助。

+0

如何在加密和解密時在GUI上顯示進度? –

+0

用進度條(Visual Studio提供了一種簡單的方法)。 – Legolas

+0

您正在使用哪種IDE(集成開發環境(Code :: Blocks,Visual Studio等))? – Legolas