diff --git a/README.md b/README.md index f22d2b5a038b320d8afac7cd6db1f50b8f4f685e..2e3d78f07badb16d0c2305121d03b12bef0defe6 100644 --- a/README.md +++ b/README.md @@ -2,58 +2,8 @@ -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.fokus.fraunhofer.de/lou62437/qsns2025.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.fokus.fraunhofer.de/lou62437/qsns2025/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - ## Name -Choose a self-explaining name for your project. +Implementation of the [Pubilcation](about:blank) for the QSNS2025 workshop. ## Description Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. @@ -65,7 +15,10 @@ On some READMEs, you may see small images that convey metadata, such as whether Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. ## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. +Versions used in this project: +- Sage 10.4 +- Python 3.11.10 +- fyplll 0.6.1 ## Usage Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. diff --git a/main.sage b/main.sage index 3df4421bde94b57a7721e13d9849d6211694e58d..a9baea40da0eae29bad8e652c34e8963b66d0416 100644 --- a/main.sage +++ b/main.sage @@ -1,8 +1,13 @@ +from fpylll import LLL, BKZ, IntegerMatrix, GSO +from fpylll.algorithms.bkz2 import BKZReduction as BKZ2 from sage.all import * from sage.crypto.lwe import samples, LWE +import time +import multiprocessing +from numpy import zeros, nan -from tools import * -from plots import * +from tools import CenteredBinomialDistibution, SVPreduction, calculate_t, score, makenumpy +from plots import plot_lll, plot_bkz def nistlike(n, q): """ @@ -48,7 +53,7 @@ def bkz_with_blocksize(instance): q = instance[4] b = instance[5] B = SVPreduction(A, t, q) - params = BKZ.Param(b, strategies=BKZ.DEFAULT_STRATEGY, flags=BKZ.VERBOSE|BKZ.AUTO_ABORT) + params = BKZ.Param(b, strategies=BKZ.DEFAULT_STRATEGY, flags=BKZ.AUTO_ABORT) bkz = BKZ2(GSO.Mat(B, float_type='mpfr')) try: bkz(params) @@ -58,7 +63,7 @@ def bkz_with_blocksize(instance): s_best = B_np[0][:n] e_best = B_np[0][n:-1] sc = score(t, s_best, e_best, A, s, p) - if sc == 0: + if sc: return True else: return False @@ -86,7 +91,7 @@ for p in pp: s_best = B_np[0][:n] e_best = B_np[0][n:2*n] sc = score(t, s_best, e_best, A, s, p) - if sc == 0: + if sc: x[k] += 1 x[k] = x[k] / tries output = open('lll_results.txt', 'a') @@ -101,7 +106,7 @@ plot_lll() # Run BKZ tries = 256 pp = [71, 401, 3329] -nn = range(8, 81, 8) +nn = range(8, 113, 8) blocks = [8, 16, 24, 32, 40, 48, 56] for p in pp: diff --git a/plots.py b/plots.py index d47a23f0274ade562a61799955722f80cc1fb6b4..3b6ee8949c9436ce6d793e59498c49236d5e3705 100644 --- a/plots.py +++ b/plots.py @@ -1,5 +1,5 @@ import matplotlib.pyplot as plt -from numpy import log, exp, linspace, inf +from numpy import exp, linspace, inf from scipy.optimize import curve_fit import scienceplots plt.style.use(["science", "grid"]) @@ -60,7 +60,7 @@ def plot_lll(filepath='results_lll.txt'): plt.show() -def plot_bkz(filename='bkz_results.txt'): +def plot_bkz(filename='bkz_results.txt', show_time=False, prime_for_time=401): d = open(filename, 'r') nn, pp, bb, score, time, sample = [], [], [], [], [], [] l = d.readline() @@ -111,10 +111,10 @@ def plot_bkz(filename='bkz_results.txt'): print(block, module, keylength) block_plot = list(set(bb)) block_plot.sort() + block_plot.remove(2) primes = list(set(pp)) primes.sort() k = 0 - x_val = linspace(1, 80, 1001) for prime in primes: plt.figure(figsize=(4,4)) for block in block_plot: @@ -134,23 +134,23 @@ def plot_bkz(filename='bkz_results.txt'): legend.get_frame().set_linewidth(0.5) plt.xlabel(r'Key length $n$', fontsize=12) plt.ylabel(r'Probability $p$', fontsize=12) - plt.title(f'Prime: {prime}') - plt.figure(figsize=(6,4)) - k = 0 - for keylength in n: - if keylength > 40: - b = [] - times = [] - for blocks in block_plot: - b.append(blocks) - times.append(results[blocks][401][keylength]['time']) - plt.plot(b, times, marker=marker[k], linestyle='-', markersize=5, color=col[k], fillstyle='none', label=fr"$n$ = {keylength}") + if show_time: + plt.figure(figsize=(6,4)) + k = 0 + for keylength in n: + if keylength > 40: + b = [] + times = [] + for blocks in block_plot: + b.append(blocks) + times.append(results[blocks][prime_for_time][keylength]['time']) + plt.plot(b, times, marker=marker[k], linestyle='-', markersize=5, color=col[k], fillstyle='none', label=fr"$n$ = {keylength}") - k += 1 - legend = plt.legend(fancybox=False, edgecolor="black", bbox_to_anchor=(1.05, 1.0), loc='upper left') - legend.get_frame().set_linewidth(0.5) - plt.tight_layout() - plt.xlabel(r'Block size $\beta$', fontsize=12) - plt.ylabel(r'Time $t\: [s]$', fontsize=12) - plt.yscale('log') - plt.show() + k += 1 + legend = plt.legend(fancybox=False, edgecolor="black", bbox_to_anchor=(1.05, 1.0), loc='upper left') + legend.get_frame().set_linewidth(0.5) + plt.tight_layout() + plt.xlabel(r'Block size $\beta$', fontsize=12) + plt.ylabel(r'Time $t\: [s]$', fontsize=12) + plt.yscale('log') + plt.show() diff --git a/tools.py b/tools.py index c2aa883f651aa7d96d3f87ac5415e72ed7d2e074..71974149a06828925b34a190ee2d545857215aca 100644 --- a/tools.py +++ b/tools.py @@ -1,5 +1,4 @@ -from fpylll import LLL, BKZ, IntegerMatrix, GSO -from fpylll.algorithms.bkz2 import BKZReduction as BKZ2 +from fpylll import IntegerMatrix from numpy import zeros, array, matrix, dot, arange, nan from numpy.linalg import norm import random @@ -106,4 +105,4 @@ def score(t, ss, ee, A, s, p): t[k] = t[k] - p if tt[k] >= p//2: tt[k] = tt[k] - p - return int(norm(t-tt, ord=1)) + return t==tt