そこで、パスワード文字列を要求し、それを使用してISAACをシードする基本的な xor 暗号化プログラムを作成しました。
次に、文字列を暗号化するように要求し、ISAAC からの出力と xor します。何らかの理由で、これは同じ 2 つの文字列に対して一定でない結果を生成しています。これは私のコードの問題ですか、それともコンソールに出力されているのでしょうか? 私はそれを明白にするために何かをしていますか?これが私のコードです。ISAAC のサイトで提供されているテンプレート クラスを使用しています。
#include <iostream>
#include <cstdlib>
using std::malloc;
using std::free;
#include "isaac.hpp"
#include <time.h>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;
QTIsaac<8,int> derp;
char trand(){
int rando=0;
rando=derp.rand();
rando=abs(rando);
rando=rando%256;
char re=rando;
return re;
}
int main()
{
cout << "What is your password string?\n";
string get;
getline(cin,get);
int length=get.size();
int seedWithMe[length];
for(int i=0;i<length;i++){
seedWithMe[i]=(int)get[i];
}
derp.srand(1,1,1,seedWithMe);
cout << "What is your string to be encrypted? \n";
getline(cin,get);
length=get.size();
char table[length];
char table3[length];
for(int i=0;i<length;i++){
table[i]=trand();
}
for(int i=0;i<length;i++){
table3[i]=(char)table[i]^(char)get[i];
}
cout << table3 << "\n";
return 0;
}
編集:気にしないでください、それはすべて私が愚かだっただけです
そのため、David Schwartz から提供された修正を試みましたが、パスワードをハッシュしようとすると、再び機能しなくなりました。入力文字列をハッシュするために使用している関数は次のとおりです。
string shaOfPass(string digestThis){ string digest; CryptoPP::SHA256 hash;
CryptoPP::StringSource foo(digestThis, true, new CryptoPP::HashFilter(hash, new CryptoPP::HexEncoder ( new CryptoPP::StringSink(digest)))); return digest; } And this code results in inconstant output:
cout << "What is your password string?\n"; string get; getline(cin,get); string hashOfPass=shaOfPass(get); int seedWithMe[256]; for(int i=0;i<256;i++){ seedWithMe[i]=(int)get[i%256]; }