Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdint>
- #include <cstdio>
- #include <bitset>
- #include<iostream>
- struct xws { __uint128_t x, weyl, s; };
- struct xws initializer(__uint128_t x_init, __uint128_t weyl_init, const __uint128_t s_init)
- {
- __uint128_t x = 0;
- __uint128_t weyl = 0;
- __uint128_t s = 0;
- for (int i = 0; i < 128; i++)
- {
- x_init = (-(x_init & 1) & (x_init + ((x_init + 1) >> 1)) | ~- (x_init & 1) & (x_init >> 1)) ^ (weyl_init += s_init);
- x += (x & 1) << i;
- }
- for (int i = 0; i < 128; i++)
- {
- x_init = (-(x_init & 1) & (x_init + ((x_init + 1) >> 1)) | ~- (x_init & 1) & (x_init >> 1)) ^ (weyl_init += s_init);
- weyl += (x & 1) << i;
- }
- for (int i = 0; i < 128; i++)
- {
- x_init = (-(x_init & 1) & (x_init + ((x_init + 1) >> 1)) | ~- (x_init & 1) & (x_init >> 1)) ^ (weyl_init += s_init);
- s += (x & 1) << i;
- }
- return xws{x, weyl, s | 1 };
- }
- struct xw { __uint128_t x, weyl; };
- struct xw skip(__uint128_t x, __uint128_t weyl, const __uint128_t s)
- {
- for (int i = 0; i < 128; i++)
- {
- x = (-(x & 1) & (x + ((x + 1) >> 1)) | ~- (x & 1) & (x >> 1)) ^ (weyl += s);
- }
- return xw{ x, weyl };
- }
- __uint128_t next(__uint128_t& x, __uint128_t& weyl, const __uint128_t& s)
- {
- __uint128_t v = 0;
- for (int i = 0; i < 128; i++)
- {
- x = (-(x & 1) & (x + ((x + 1) >> 1)) | ~-(x & 1) & (x >> 1)) ^ (weyl += s);
- v += (x & 1) << i;
- }
- return v;
- }
- int main()
- {
- const __uint128_t key = 1234321; //it has to be odd
- const __uint128_t x_init = key, weyl_init = key, s_init = key;
- xws initialization = initializer(x_init, weyl_init, s_init);
- __uint128_t x = initialization.x;
- __uint128_t weyl = initialization.weyl;
- __uint128_t s = initialization.s;
- xw skipping = skip(x, weyl, s);
- x = skipping.x;
- weyl = skipping.weyl;
- uint64_t result = 0;
- for(int i=0; i<25; i++)
- {
- result = next(x, weyl, s);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment