randomPositions method

Map randomPositions(
  1. String role,
  2. String hash,
  3. int numberOfPositions,
  4. List<int> pvt1,
)

Implementation

Map randomPositions(
    String role, String hash, int numberOfPositions, List<int> pvt1) {
  int u = 0, l = 0, m = 0;
  var hashCharacters =
      new List<int>.generate(32, (index) => 0, growable: false);
  var randomPositions =
      new List<int>.generate(32, (index) => 0, growable: false);
  var randPos = new List<int>.generate(256, (index) => 0, growable: false);
  var originalPos = new List<int>.generate(32, (index) => 0, growable: false);
  List<int> posForSign = new List<int>.generate(32 * 8, (index) => 0);
  for (int k = 0; k < numberOfPositions; k++) {
    String hashVar = hash.substring(k, k + 1);
    hashCharacters[k] = int.parse(hashVar, radix: 16);
    randomPositions[k] = (((2402 + hashCharacters[k]) * 2709) +
            ((k + 2709) + hashCharacters[(k)])) %
        2048;
    originalPos[k] = ((randomPositions[k] ~/ 8) * 8);
    var pos = new List<int>.generate(32, (index) => 0, growable: false);
    pos[k] = originalPos[k];
    randPos[k] = pos[k];
    var finalPositions =
        new List<int>.generate(8, (index) => 0, growable: false);
    for (int p = 0; p < 8; p++) {
      posForSign[u] = randPos[k];
      randPos[k]++;
      u++;
      finalPositions[l] = pos[k];
      pos[k]++;
      l++;
      if (l == 8) {
        l = 0;
      }
    }

    if (role == "signer") {
      List<int> p1 = new List<int>.generate(8, (index) => 0, growable: false);
      p1 = getPrivatePosition(finalPositions, pvt1);

      hash = Dependencies()
          .calculateHash((hash) + intArrayToStr(originalPos) + intArrayToStr(p1));
    } else {
      List<int> p1 = new List<int>.generate(8, (index) => 0, growable: false);
      for (int i = 0; i < 8; i++) {
        p1[i] = pvt1[m];
        m++;
      }

      hash = Dependencies()
          .calculateHash((hash) + intArrayToStr(originalPos) + p1.join());
    }
  }

  Map<String, List<int>> resultObject = {
    "originalPos": originalPos,
    "posForSign": posForSign,
  };

  return resultObject;
}