public bool IsIn(Position searchPosition) { var encoded = GetEncodedPosition(searchPosition); var evaluator = new Evaluator(GetContext()); PositionEncrypted positionEncrypted = GetFromIota(); evaluator.SubPlain(positionEncrypted.Lon, encoded.Lon); evaluator.SubPlain(positionEncrypted.Lat, encoded.Lat); var decryptor = new Decryptor(GetContext(), GetSecretKey()); Plaintext plainResultLon = new Plaintext(); Plaintext plainResultLat = new Plaintext(); decryptor.Decrypt(positionEncrypted.Lon, plainResultLon); decryptor.Decrypt(positionEncrypted.Lat, plainResultLat); var encoder = GetEncoder(GetContext()); double resultLon = encoder.Decode(plainResultLon); double resultLat = encoder.Decode(plainResultLat); var diff = Math.Abs(resultLon) + Math.Abs(resultLat); if (diff < 0.007) { return(true); } return(false); }
public void EncryptValues(Position position, out PositionEncrypted positionEncrypted) { var encryptor = new Encryptor(GetContext(), GetPublicKey()); PositionEncoded positionEncoded = GetEncodedPosition(position); positionEncrypted = GetEncrpytedPosition(positionEncoded, encryptor); }
private PositionEncrypted GetEncrpytedPosition(PositionEncoded position, Encryptor encryptor) { PositionEncrypted positionEncrypted = new PositionEncrypted(); encryptor.Encrypt(position.Lon, positionEncrypted.Lon); encryptor.Encrypt(position.Lat, positionEncrypted.Lat); return(positionEncrypted); }
private PositionEncrypted GetFromIota() { const string address = "IOTAFFFBLOCKCHAINEDMOBILITYHACKATHONTHEBLOCKCHAINEDMOBILITYHACKATHONTHEBLOCKCHAIN"; IotaHelperWithSpecialPower iotaHelper = new IotaHelperWithSpecialPower(); PositionEncrypted encrypted = iotaHelper.GetPosition(address); return(encrypted); }
public PositionEncrypted GetPosition(string address) { int depth = 3; int minWeightMagnitude = 9; PositionEncrypted positionEncrypted = new PositionEncrypted(); try { TransactionHashList transactionsByAdress = _Repository.FindTransactionsByAddresses(new List <Address> { new Address(address) }); List <TransactionTrytes> transactionsTrytesList = _Repository.GetTrytes(transactionsByAdress.Hashes); Dictionary <int, Transaction> transactionPosition = new Dictionary <int, Transaction>(); int lastIndex = 0; foreach (TransactionTrytes transactionTrytes in transactionsTrytesList) { Transaction transactionOne = Transaction.FromTrytes(transactionTrytes, transactionsByAdress.Hashes[0]); transactionPosition.Add(transactionOne.CurrentIndex, transactionOne); lastIndex = transactionOne.LastIndex; } string combined = string.Empty; for (int i = 0; i <= lastIndex; i++) { combined += transactionPosition[i].Fragment.Value; } string fertisch = TrytesToString(combined); string[] lines = fertisch.Split(new[] { "#" }, StringSplitOptions.None); positionEncrypted = new PositionEncrypted(); positionEncrypted.Lon = new Ciphertext(); positionEncrypted.Lon.Load(new MemoryStream(Convert.FromBase64String(lines[0]))); positionEncrypted.Lat = new Ciphertext(); positionEncrypted.Lat.Load(new MemoryStream(Convert.FromBase64String(lines[1]))); } catch (Exception exception) { Console.WriteLine(exception); //throw; } return(positionEncrypted); }