逐行散列文件时错误的 md5 散列值

Wrong md5 hash values when hashing a file line by line

我的程序尝试逐行散列文件 Passwords.txt。然而,每次它这样做时,所有的散列值都不正确。

void Rainbow::generateTable(string filename)
{
    //noOfLines=0;
    //bitsToRemove=0;

    ifstream myfile("Passwords.txt");

    if (myfile)
    {

        string line;

        while (getline(myfile, line))
        {
            noOfLines++;                         
        }
     }


    cout << "File is " << noOfLines << " lines long!" << endl;


    toRoundUp = log2(noOfLines);

    cout << "toRoundUp is " << toRoundUp << endl;
    bitsToRemove = ceil(toRoundUp);

    cout << "bitsToRemove is " << bitsToRemove << endl;

    //myfile.close();

    ifstream file("Passwords.txt");
    string myline;

    if (file.is_open())
    {



        while (getline(file,myline))
        {

            cout << md5(myline) << endl;


        }

    }




    displayMenu();


}

然而,当我尝试这样的事情时:散列值是正确的

cout << md5("one") << endl;

Passwords.txt内容如下:

one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty

这些是我的程序输出的哈希值:

945da772b285bb656550d0c2b94ef80c
9d6ec883255ab3527cd340baad797de5
e119d725f6a7b5413a61da21e7232cd5
31897146a8acc1eede32b7cbf4280f86
d97ee990314c796d0cfbedf39dc9d716
b27f9179c0570da135ec7c7f71c06692
b5e416cbaa6b63b46bf6975b2f365bfe
684349fb14f1cd243d91699a03c00b00
67ed2e62351f8e26e2ba17c30075f8be
41be321de3beb1474b2281bbbe4c8115
59bb31725256bd2af6d0b45d6372ff7a
ac573bd3385c4c0a19d5998bd16b3c0a
aae690fe1db712f89101e6665eccdb4a
93cfff3ce14123aa984447d33cd7fbe4
f35aa54743fa6bb0b8a319e55f8830ae
f516ed17f1fefe016cb3a3a398745682
f81da1a9d89b53a89fc71113ff9da7dd
aac5308f9cd346f9a11b9ff510ebd355
5178aa7f04124a2b930aa02abd9dc7f1
067636f2e9b0852519f85c2a33782b00

非常感谢任何帮助!

如@Biffen 所述,使用 nano 创建文件并通过 Ubuntu GUI 创建文件会导致 EOL 的差异。因此,我需要做的就是丢弃现有文件并通过 Ubuntu GUI 创建一个 "identical" 文件。