正如文章標題暗示的工作,我的工作,以加強我的基於C++的把握和人物操縱,此時通過創建一個V @ genere加密。對於那些不熟悉它的人來說,這是一個相當簡單的加密文本文件的方式。自制Vigenere t密碼;與ACSII字符處理
它的基本工作方式是存在一個字符串「key」,每個字符(至少在我的情況下)是一個小寫字母字符。這些被存儲到一個數組中,並用於「移位」正在編碼的文件的值。 'a'的字符會將目標移動0,而'z'會將它移動25。「移動」是週期性的,這意味着如果'z'移動'b'(1),它應該導致'一個'。
我當前的方法如下發現:
//Assume cipher[] contains "[a][b][c][x ][y ][z ]" Cipher is a <string> object
//Assume ptr[] contains "[0][1][2][23][24][25]
#A whole bunch of includes
char c;
ifstream is;
ofstream os;
is.open(argv[3]) //"myinput.txt"
os.open(argv[4]) //"myoutput.txt"
int i = 0;
while(is.good()) {
c = is.get();
if(is.good()) { //did we just hit the EoF?
c = tolower(c - 0); //just make sure it's lowercase
c = c + ptr[ i % cipher.size() ] % 26;
if(c> 122)
c = (c % 123) + 97;
i++;
os.put(c);
}
}
我的問題在於我的模運算,我相信。也許是因爲我花了這麼多時間哈希這一點,但我花了幾個小時昨晚寫這個,然後一小時躺在牀上想換我圍繞着如何有效地建立心靈,猶如我想:
grab char.
check char. //let char = 'z'
check the cipher. //let the cipher = 'y'
eval cipher shift //'y' shift value = 24
shift z 24 places (cyclically) //'z'==25, 25+24=49, 49%26=23. 23='x'
這是問題:如何用ACSII做到這一點? ('a'= 97,z ='121')