1
0
mirror of https://github.com/biergaizi/codecrypt synced 2024-06-29 18:33:10 +00:00
codecrypt/src/generator.h

48 lines
1.1 KiB
C
Raw Normal View History

/*
* This file is part of Codecrypt.
*
* Codecrypt is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Codecrypt is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Codecrypt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _ccr_generator_h_
#define _ccr_generator_h_
#include "arcfour.h"
#include "prng.h"
class arcfour_rng : public prng
{
public:
arcfour<byte> r;
arcfour_rng() {
r.init (8);
}
~arcfour_rng() {
r.clear();
}
2013-01-13 22:27:21 +00:00
void seed (uint bits, bool quick = true);
uint random (uint n) {
//rand_max is 2^32.
2013-04-21 07:59:55 +00:00
return ( (r.gen() << 24) | (r.gen() << 16)
| (r.gen() << 8) | r.gen() ) % n;
}
};
#endif