2014-01-29 74 views
0

我正在C++中製作一個小密碼強度計算器,它將計算密碼的信息熵值以及NIST值。我有程序的熵部分工作,但NIST部分給我一些問題。我很確定我有正確的公式,但每次我把我的測試密碼通過我知道應該給我的值24我得到了18的值。我沒有看到在我的代碼中會導致這個問題導致我相信這是公式的問題。有人熟悉NIST配方,可以提供幫助嗎?任何幫助將不勝感激。下面附上了我的代碼。C++中的密碼強度

#include <iostream> 
#include <cmath> 
#include <string> 
using namespace std; 

int main(){ 
    string eight_password, first_char, next_seven; 
    int ep_length; 
    double ent_strength, nist_strength; 
    const int NIST_FIRST = 4, NIST_SEVEN = 2, NIST_REM = 1; 
    const double NIST_TWELVE = 1.5; 
    cout << "Hello! Please enter a password of 8 characters or less (including spaces!):" << endl; 
    getline(cin, eight_password); 
    ep_length = eight_password.length(); 
    ent_strength = (ep_length*((log(94))/(log(2)))); 
    first_char = eight_password.substr(0, 1); 
    next_seven = eight_password.substr(1, 7); 
    nist_strength = (first_char.length()*NIST_FIRST) + (next_seven.length()*NIST_SEVEN); 
    cout << nist_strength<<endl; 
    cout << first_char.length() << endl; 
    cout << next_seven.length() << endl; 
    return 0; 
} 
+1

如果你添加一個鏈接到規範 –

+0

[Go Here](http://en.wikipedia.org/wiki/Password_strength),並向下滾動到「NIST Special Publication 800-63」 – user3064203

回答

2

此公式

nist_strength = (first_char.length()*NIST_FIRST) + (next_seven.length()*NIST_SEVEN); 

總是產生18,因爲它沒有考慮到密碼的組合物在所有。它只考慮其第一個和接下來七個字符的長度,總是1 * 4 + 7 * 2 = 18。該標準定義了基於密碼組成的不同評估方法,即所有低/高,低+高,低+高+數字等。

我建議你設置兩個變量n1,n7和在檢查第一個和下一個7個字符是基於標準之後計算它們的值,然後在公式中使用它們。

希望這會有所幫助。