■
多倍長整数の乱数を生成する方法についてもう少し詳しく考えてみた。
生成した乱数を桁数をLとする 種を生成する(srand(),rand()を16回行い64バイトの整数を生成) 種を初期カウンタ値としてセットする while (true) { カウンタ値をハッシュ関数(md5)にかけハッシュ値(128bit)を擬似乱数として 多倍長整数にセットしていく if (多倍長整数にセットされた桁数 >= L) break; カウンタ値をインクリメントする }
とりあえずこれで実装しよう。
多倍長整数はRSA専用として実装していくことにしよう。多倍長整数の演算速度に関しては一切気にせずに行う事にする。
まずは多倍長整数の実装を考える。
多倍長整数クラスBIGINTに必要な演算子オーバーロードは以下の感じだろうか
BIGINT& operator=(const BIGINT& org) BIGINT operator+(const BIGINT& org) BIGINT& operator+=(const BIGINT& org) BIGINT operator-(const BIGINT& org) BIGINT& operator-=(const BIGINT& org) BIGINT& operator++() BIGINT operator++(int dummy) BIGINT& operator--() BIGINT operator--(int dummy) bool operator>(const BIGINT& org) bool operator<(const BIGINT& org) bool operator>=(const BIGINT& org) bool operator<=(const BIGINT& org) bool operator==(const BIGINT& org) bool operator!=(const BIGINT& org)
あとはコンストラクター
BIGINT() BIGINT(const BIGINT& org) BIGINT(vector::iterator first, vector ::iterator end)
とりあえずこんなもんで。思いついたらどんどん追加。