所以我提出,從ISAAC輸出要求輸入密碼字符串,並用它來種子ISAAC我在做什麼導致這個程序的輸出不一致?
然後選出要加密的字符串和XOR的一項基本XOR加密程序。 由於某些原因,這對於相同的兩個字符串會產生不穩定的結果。 這是我的代碼問題,還是它被輸出到控制檯? 我在做些什麼讓它顯而易見? 這裏是我的代碼,我使用的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;
}
編輯:沒關係,這一切只是我太傻了
所以,我試圖修復大衛·施瓦茨給了我,但後來當我試圖 哈希密碼,它再次退出工作。我使用的 散列輸入字符串的功能是:
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]; }
這個程序是非法的C++。你不能聲明'char table [length]',其中'length'不是一個常量。 – 2011-12-20 21:34:36
乍一看問題是'table'的值在每次運行時會有所不同,因此您的輸出將是不確定的。 – Matyas 2011-12-20 21:36:38
@Alexandre C .:'gcc'允許它(但你是對的,它不是標準的一部分)。 – bitmask 2011-12-20 21:38:43