galois

by evgkch

JavaScript

class VectorSet {
	constructor(depth) {
  	this._map = {};
  }
  add(vec) {
  	this._map[vec.join('')] = true;
  }
  has(vec) {
  	return !!this._map[vec.join('')];
  }
  delete(vec) {
  	delete this._map[vec.join('')];
  }
}

class ModMat2 {
	get a() {
  	return this._arr[0];
  }
  get b() {
  	return this._arr[1];
  }
  get c() {
  	return this._arr[2];
  }
  get d() {
  	return this._arr[3];
  }
	constructor(mod, [a, b, c, d]) {
  	this.mod = mod;
  	this._arr = [
    	a % mod, b % mod,
      c % mod, d % mod
    ];
  }
  multiply(mat) {
  	return new ModMat2(this.mod, [
    	this.a * mat.a + this.b * mat.c, this.a * mat.b + this.b * mat.d,
      this.c * mat.a + this.d * mat.c, this.c * mat.b + this.d * mat.d
    ]);
  }
  toString() {
  	return this._arr.join('');
  }
}

function main(p) {     
  for (let a = 0; a < p; a++) {
  	for (let b = 0; b < p; b++) {
    
    	let A = new ModMat2(p, [0, b, 1, a]);
      let B = A;
    
			let set = new Set;
      
    	let count = 1;
      
      set.add(A.toString());
      
    	while(count < p ** 2 - 1) {
      	B = A.multiply(B);
        if (set.has(B.toString())) {
          break;
        } else {
        	set.add(B.toString());
        }
        
        //console.log(B)
        
        count++;
        if (count === p ** 2 - 1 && B.toString() === '1001') {
        	console.log([b, a])
        }
      }
    }
  }
}

main(5)