Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- #define pb emplace_back
- #define AI(i) begin(i), end(i)
- template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
- template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
- #ifdef KEV
- #define DE(args...) kout("[ " + string(#args) + " ] = ", args)
- void kout() { cerr << endl; }
- template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
- template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
- #else
- #define DE(...) 0
- #define debug(...) 0
- #endif
- // My bug list :
- // integer overflow
- // 0based, 1based forgotten
- // index out of bound
- // n, m, i, j typo
- // some cases are missing
- const int MAX_N = 300010;
- struct LFSR {
- int state, tap, len;
- int getbit() {
- int ret = state & 1;
- int f = __builtin_popcount(state & tap) & 1;
- state = (state >> 1) | (f << (len-1));
- return ret;
- }
- LFSR(vector<int> taps, int state, int len) :
- state(state), len(len) {
- for (int i : taps)
- tap |= 1 << i;
- }
- };
- ostream& operator << (ostream& out, LFSR b) {
- for (int i = 0;i < b.len;++i) out << (b.state>>i&1);
- return out;
- }
- const vector<int> output = {1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1};
- const int flag_len = output.size() - 200;
- int most_same;
- int check(LFSR a) {
- int same = 0;
- for (int i = 0;i < flag_len;++i)
- a.getbit();
- for (int i = flag_len;i < output.size();++i)
- same += a.getbit() == output[i];
- chmax(most_same, same);
- return same;
- return same >= 150;
- }
- LFSR find_first(vector<int> taps, int len) {
- DE(len);
- int mb = 0;
- int sm = 0;
- LFSR ret = LFSR(taps, 1, 1);
- for (int s = 0;s < 1<<len;++s) {
- if (chmax(sm, check(LFSR(taps, s, len)))) {
- ret = LFSR(taps, s, len);
- DE(sm);
- }
- //if (check(LFSR(taps, s, len)))
- //return LFSR(taps, s, len);
- }
- return ret;
- //__builtin_unreachable();
- }
- struct trilLFSR {
- LFSR a, b, c;
- trilLFSR(LFSR a, LFSR b, LFSR c) :
- a(a), b(b), c(c) {}
- int getbit() {
- int x = a.getbit(), y = b.getbit(), z = c.getbit();
- return x ? y : z;
- }
- };
- bool check1(trilLFSR g) {
- for (int i = 0;i < flag_len;++i) {
- g.getbit();
- }
- for (int i = flag_len;i < output.size();++i) {
- if (g.getbit() != output[i]) return false;
- }
- return true;
- }
- void getflag(trilLFSR g) {
- char c = 0;
- for (int i = 0;i < flag_len;++i) {
- if (i % 8 == 0) {
- cout << c;
- c = 0;
- }
- c = (c << 1) | (g.getbit() ^ output[i]);
- }
- }
- int32_t main() {
- ios_base::sync_with_stdio(0), cin.tie(0);
- auto lfsr2 = find_first({0, 5, 7, 22}, 23);
- DE(most_same);
- return 0;
- auto lfsr3 = find_first({0, 17, 19, 24}, 25);
- DE(lfsr2, lfsr3);
- return 0;
- const vector<int> lfsr1_p = {0, 13, 16, 26};
- const int lfsr1_sz = 27;
- for (int s = 0;s < 1<<27;++s) {
- auto lfsr1 = LFSR(lfsr1_p, s, lfsr1_sz);
- if (check1(trilLFSR(lfsr1, lfsr2, lfsr3)))
- getflag(trilLFSR(lfsr1, lfsr2, lfsr3));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement