さて、私は大学のクラス用のプログラムを作成しています。これは、構造を使用して、ユーザー名とパスワードとともにユーザー情報のデータベースの構築をシミュレートする単純なプログラムです。ラボの追加クレジットとして、パスワードを暗号化できます。これは特別なことではありません....MD5 やそのような高度なものは使用していません。
私がする必要があるのは、大文字を小文字に、小文字を大文字に、そして最後に、10進数の整数を16進数に変換するのに問題がある部分を切り替えることができることです。
プログラム全体ではなく、関連する部分だけを投稿するようにします。
構造は次のとおりです。
struct Info
{
string sFname;
string sLname;
string sUname;
string sPword;
string sAddress;
string sEmail;
string sPhone;
};
注: これは構造体の動的配列です。
Info *Users;
Users = new Info[size];
そして、これまでに持っているパスワードを暗号化するコードは次のとおりです。
//string length for controlling loops
strlen = Users[iUsrCount].sPword.length();
//temp string to hold the encrypted version of password
string temp;
//switch uppercase characters to lowercase and vice versa, and convert
//decimal integers into hexadecimal
for(int i=0; i<strlen; i++)
{
cout << "\n\nInside encryption for loop iteration " << i << "\n\n";
if(islower(Users[iUsrCount].sPword[i]))
{
temp += toupper(Users[iUsrCount].sPword[i]);
continue;
}
else if(isupper(Users[iUsrCount].sPword[i]))
{
temp += tolower(Users[iUsrCount].sPword[i]);
continue;
}
else if(isdigit(Users[iUsrCount].sPword[i]))
{
char charNum = Users[iUsrCount].sPword[i];
int iDec = charNum - '0';
//get integer
while((i+1) < strlen && isdigit(Users[iUsrCount].sPword[i+1]))
{
i++;
iDec = iDec * 10 + Users[iUsrCount].sPword[i] - '0';
cout << " " << iDec << " ";
}
char hexTemp[10];
//convert
sprintf(hexTemp, "%x", iDec);
temp += hexTemp;
//debugging cout to make sure hexes are properly calculated
cout << " " << hexTemp << " ";
continue;
}
}
//debugging cout to make sure that password is properly encrypted
cout << endl << endl << temp << endl << endl;
strlen = temp.length();
//overwrite the plain text password with the encrypted version
for(int i=0; i<strlen; i++)
Users[iUsrCount].sPword[i] = temp[i];
//debugging cout to make sure copy was successful
cout << endl << endl << Users[iUsrCount].sPword;
したがって、パスワードが次の場合:
456Pass45word87
暗号化すると、次のようになります。
1c8pASS2dWORD57
文字列を逆にする必要もありますが、それはかなり簡単です。
私の2つの質問はこれです:
これを行う簡単な方法はありますか?
私の人生では、パスワードを復号化するための正しいアルゴリズムを理解することはできません。これは、ユーザーがログインしたときに、コンピューターが入力内容をプレーンテキストバージョンのパスワードと比較できるようにする必要があります。
注: 私はプロのコーダーではありません。私はいたるところを見てきましたが、私の特定の状況で本当に役立つものは何も見つかりません.
そして、私はインターネットのなすがままに身を投じます。:D