Skip to content

Commit

Permalink
Fixed dotnet/3_levels.cs and wrong setup of plainmodulus.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei Dai committed Nov 28, 2019
1 parent a829d63 commit 410611f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 77 deletions.
21 changes: 12 additions & 9 deletions dotnet/examples/3_Levels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ special prime +---------+
In this example the PlainModulus does not play much of a role; we choose
some reasonable value.
*/
parms.PlainModulus = new SmallModulus(1 << 20);
parms.PlainModulus = PlainModulus.Batching(polyModulusDegree, 20);//new SmallModulus(1 << 20);

SEALContext context = new SEALContext(parms);
Utilities.PrintParameters(context);
Expand Down Expand Up @@ -241,22 +241,25 @@ is no need or intention to perform any further computations on a given
parameters in the chain before sending it back to the secret key holder for
decryption.
Also the lost noise budget is actually not as issue at all, if we do things
Also the lost noise budget is actually not an issue at all, if we do things
right, as we will see below.
First we recreate the original ciphertext and perform some computations.
*/
Console.WriteLine("Computation is more efficient with modulus switching.");
Utilities.PrintLine();
Console.WriteLine("Compute the fourth power.");
Console.WriteLine("Compute the eight power.");
encryptor.Encrypt(plain, encrypted);
Console.WriteLine(" + Noise budget before squaring: {0} bits",
Console.WriteLine(" + Noise budget fresh: {0} bits",
decryptor.InvariantNoiseBudget(encrypted));
evaluator.SquareInplace(encrypted);
evaluator.RelinearizeInplace(encrypted, relinKeys);
Console.WriteLine(" + Noise budget after squaring: {0} bits",
Console.WriteLine(" + Noise budget of the 2nd power: {0} bits",
decryptor.InvariantNoiseBudget(encrypted));
evaluator.SquareInplace(encrypted);
evaluator.RelinearizeInplace(encrypted, relinKeys);
Console.WriteLine(" + Noise budget of the 4th power: {0} bits",
decryptor.InvariantNoiseBudget(encrypted));

/*
Surprisingly, in this case modulus switching has no effect at all on the
noise budget.
Expand All @@ -272,11 +275,11 @@ modulus after doing enough computations. In some cases one might want to
switch to a lower level slightly earlier, actually sacrificing some of the
noise budget in the process, to gain computational performance from having
smaller parameters. We see from the print-out that the next modulus switch
should be done ideally when the noise budget is down to around 81 bits.
should be done ideally when the noise budget is down to around 25 bits.
*/
evaluator.SquareInplace(encrypted);
evaluator.RelinearizeInplace(encrypted, relinKeys);
Console.WriteLine(" + Noise budget after squaring: {0} bits",
Console.WriteLine(" + Noise budget of the 8th power: {0} bits",
decryptor.InvariantNoiseBudget(encrypted));
evaluator.ModSwitchToNextInplace(encrypted);
Console.WriteLine(" + Noise budget after modulus switching: {0} bits",
Expand All @@ -289,7 +292,7 @@ can be used to decrypt a ciphertext at any level in the modulus switching
chain.
*/
decryptor.Decrypt(encrypted, plain);
Console.WriteLine(" + Decryption of fourth power (hexadecimal) ...... Correct.");
Console.WriteLine(" + Decryption of the 8th power (hexadecimal) ...... Correct.");
Console.WriteLine($" {plain}");
Console.WriteLine();

Expand Down
62 changes: 31 additions & 31 deletions dotnet/examples/SEALNetExamples.csproj
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Authors>Microsoft Research</Authors>
<Company>Microsoft Corporation</Company>
<Description>.NET wrapper examples for Microsoft SEAL</Description>
<Copyright>Microsoft Corporation 2019</Copyright>
</PropertyGroup>

<PropertyGroup Condition="'$(Platform)'=='AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>../bin/$(Configuration)</OutputPath>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../src/SEALNet.csproj" />
</ItemGroup>

<ItemGroup>
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(Windows))" Include="$(ProjectDir)../lib/x64/$(Configuration)/sealnetnative.dll" />
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(Linux))" Include="$(ProjectDir)../lib/libsealnetnative.so.*" />
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(OSX))" Include="$(ProjectDir)../lib/libsealnetnative.*.dylib" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy SourceFiles="@(SEALNetNativeBinaryFiles)" DestinationFolder="$(TargetDir)" />
</Target>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Authors>Microsoft Research</Authors>
<Company>Microsoft Corporation</Company>
<Description>.NET wrapper examples for Microsoft SEAL</Description>
<Copyright>Microsoft Corporation 2019</Copyright>
</PropertyGroup>

<PropertyGroup Condition="'$(Platform)'=='AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>../bin/$(Configuration)</OutputPath>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../src/SEALNet.csproj" />
</ItemGroup>

<ItemGroup>
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(Windows))" Include="$(ProjectDir)../lib/x64/$(Configuration)/sealnetnative.dll" />
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(Linux))" Include="$(ProjectDir)../lib/libsealnetnative.so.*" />
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(OSX))" Include="$(ProjectDir)../lib/libsealnetnative.*.dylib" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy SourceFiles="@(SEALNetNativeBinaryFiles)" DestinationFolder="$(TargetDir)" />
</Target>

</Project>
74 changes: 37 additions & 37 deletions dotnet/tests/SEALNetTest.csproj
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
<Authors>Microsoft Research</Authors>
<Company>Microsoft Corporation</Company>
<Description>.NET wrapper unit tests for Microsoft SEAL</Description>
<Copyright>Microsoft Corporation 2019</Copyright>
</PropertyGroup>

<PropertyGroup Condition="'$(Platform)'=='AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>../lib/$(Configuration)</OutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../src/SEALNet.csproj" />
</ItemGroup>

<ItemGroup>
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(Windows))" Include="$(ProjectDir)../lib/x64/$(Configuration)/sealnetnative.dll" />
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(Linux))" Include="$(ProjectDir)../lib/libsealnetnative.so.*" />
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(OSX))" Include="$(ProjectDir)../lib/libsealnetnative*.dylib" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy SourceFiles="@(SEALNetNativeBinaryFiles)" DestinationFolder="$(TargetDir)" />
</Target>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
<Authors>Microsoft Research</Authors>
<Company>Microsoft Corporation</Company>
<Description>.NET wrapper unit tests for Microsoft SEAL</Description>
<Copyright>Microsoft Corporation 2019</Copyright>
</PropertyGroup>

<PropertyGroup Condition="'$(Platform)'=='AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>../lib/$(Configuration)</OutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../src/SEALNet.csproj" />
</ItemGroup>

<ItemGroup>
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(Windows))" Include="$(ProjectDir)../lib/x64/$(Configuration)/sealnetnative.dll" />
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(Linux))" Include="$(ProjectDir)../lib/libsealnetnative.so.*" />
<SEALNetNativeBinaryFiles Condition="$([MSBuild]::IsOsPlatform(OSX))" Include="$(ProjectDir)../lib/libsealnetnative*.dylib" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy SourceFiles="@(SEALNetNativeBinaryFiles)" DestinationFolder="$(TargetDir)" />
</Target>

</Project>

0 comments on commit 410611f

Please sign in to comment.