public void SaveLoadTest() { SEALContext context = GlobalContext.Context; KeyGenerator keyGen = new KeyGenerator(context); GaloisKeys keys = keyGen.GaloisKeys(decompositionBitCount: 30); GaloisKeys other = new GaloisKeys(); Assert.IsNotNull(keys); Assert.AreEqual(30, keys.DecompositionBitCount); Assert.AreEqual(22ul, keys.Size); using (MemoryStream ms = new MemoryStream()) { keys.Save(ms); ms.Seek(offset: 0, loc: SeekOrigin.Begin); other.Load(context, ms); } Assert.AreEqual(30, other.DecompositionBitCount); Assert.AreEqual(22ul, other.Size); Assert.IsTrue(other.IsMetadataValidFor(context)); List <IEnumerable <Ciphertext> > keysData = new List <IEnumerable <Ciphertext> >(keys.Data); List <IEnumerable <Ciphertext> > otherData = new List <IEnumerable <Ciphertext> >(other.Data); Assert.AreEqual(keysData.Count, otherData.Count); for (int i = 0; i < keysData.Count; i++) { List <Ciphertext> keysCiphers = new List <Ciphertext>(keysData[i]); List <Ciphertext> otherCiphers = new List <Ciphertext>(otherData[i]); Assert.AreEqual(keysCiphers.Count, otherCiphers.Count); for (int j = 0; j < keysCiphers.Count; j++) { Ciphertext keysCipher = keysCiphers[j]; Ciphertext otherCipher = otherCiphers[j]; Assert.AreEqual(keysCipher.Size, otherCipher.Size); Assert.AreEqual(keysCipher.PolyModulusDegree, otherCipher.PolyModulusDegree); Assert.AreEqual(keysCipher.CoeffModCount, otherCipher.CoeffModCount); ulong coeffCount = keysCipher.Size * keysCipher.PolyModulusDegree * keysCipher.CoeffModCount; for (ulong k = 0; k < coeffCount; k++) { Assert.AreEqual(keysCipher[k], otherCipher[k]); } } } }