|
@@ -1,6 +1,6 @@
|
|
|
from openfhe import *
|
|
|
|
|
|
-def main(nativeint=128):
|
|
|
+def main(nativeint=64):
|
|
|
SimpleBootstrapExample(nativeint)
|
|
|
|
|
|
def SimpleBootstrapExample(nativeint):
|
|
@@ -31,13 +31,47 @@ def SimpleBootstrapExample(nativeint):
|
|
|
levelsUsedBeforeBootstrap = 10
|
|
|
|
|
|
depth = levelsUsedBeforeBootstrap + FHECKKSRNS.GetBootstrapDepth(approxBootstrappDepth, levelBudget, secretKeyDist)
|
|
|
- print(depth)
|
|
|
+
|
|
|
parameters.SetMultiplicativeDepth(depth)
|
|
|
|
|
|
cryptocontext = GenCryptoContext(parameters)
|
|
|
cryptocontext.Enable(PKESchemeFeature.PKE)
|
|
|
cryptocontext.Enable(PKESchemeFeature.KEYSWITCH)
|
|
|
- #cryptocontext.Enable()
|
|
|
+ cryptocontext.Enable(PKESchemeFeature.LEVELEDSHE)
|
|
|
+ cryptocontext.Enable(PKESchemeFeature.ADVANCEDSHE)
|
|
|
+ cryptocontext.Enable(PKESchemeFeature.FHE)
|
|
|
+
|
|
|
+ ringDim = cryptocontext.GetRingDimension()
|
|
|
+ # This is the mazimum number of slots that can be used full packing.
|
|
|
+
|
|
|
+ numSlots = int(ringDim / 2)
|
|
|
+ print(f"CKKS is using ring dimension {ringDim}")
|
|
|
+
|
|
|
+ cryptocontext.EvalBootstrapSetup(levelBudget)
|
|
|
+
|
|
|
+ keyPair = cryptocontext.KeyGen()
|
|
|
+ cryptocontext.EvalMultKeyGen(keyPair.secretKey)
|
|
|
+ cryptocontext.EvalBootstrapKeyGen(keyPair.secretKey, numSlots)
|
|
|
+
|
|
|
+ x = [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0]
|
|
|
+ encodedLength = len(x)
|
|
|
+
|
|
|
+ ptxt = cryptocontext.MakeCKKSPackedPlaintext(x)
|
|
|
+ ptxt.SetLength(encodedLength)
|
|
|
+
|
|
|
+ print(f"Input: {x}")
|
|
|
+
|
|
|
+ ciph = cryptocontext.Encrypt(keyPair.publicKey, ptxt)
|
|
|
+
|
|
|
+ print(f"Initial number of levels remaining: {ciph.GetLevel()}")
|
|
|
+
|
|
|
+ ciphertextAfter = cryptocontext.EvalBootstrap(ciph)
|
|
|
+
|
|
|
+ print(f"Number of levels remaining after bootstrapping: {ciphertextAfter.GetLevel()}")
|
|
|
+
|
|
|
+ result = cryptocontext.Decrypt(keyPair.secretKey, ciphertextAfter)
|
|
|
+ result.SetLength(encodedLength)
|
|
|
+ print(f"Output after bootstrapping: {result}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- main()
|
|
|
+ main(64)
|