Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
reednel committed Dec 22, 2022
1 parent 3972cf4 commit 00501ad
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 40 deletions.
7 changes: 0 additions & 7 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
// }
//},

"settings": {
// General settings
"files.eol": "\n",
"rewrap.autoWrap.enabled": true,
"editor.formatOnSave": false
},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
Expand Down
32 changes: 32 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Contributing to AAG

The following guidelines are designed for contributors to AAG.

## Reporting Issues and Questions

For reporting a bug, a failed function or requesting a new feature, open an issue in GitHub's [issue tracker](https://github.com/reednel/aag/issues). First, seach through existing issues (open or closed) that might have the answer to your question.

When reporting a bug, it is most helpful to include:

- A quick background/summary
- Specific steps to reproduce, with sample code if you can
- The expected result
- The actual result
- Notes (i.e. why you think this might be happening, or things you tried that didn't work)

## Contributing Code

To make contributions to AAG, request your changes or contributions via a pull request against the `development` branch of the AAG repository.

Please use the following steps:

1. Fork the AAG repository to your GitHub account
2. Clone your fork locally with `git clone`
3. Create a new branch with a name that describes your contribution. For example, if your contribution is a bug fix in `fileio.cpp`, your new branch can be named `bugfix/fileio`. You can create and switch to it with `git checkout -b bugfix/fileio`
4. Make your changes on this new branch.
5. Push your changes to your fork.
6. [Submit a pull request](https://github.com/reednel/AAG/pulls) against the `development` branch in AAG.

## License

By contributing, you agree that your contributions will be licensed under its MIT License.
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
# Anshel-Anshel-Goldfeld

[![GitHub Releases](https://img.shields.io/github/v/release/reednel/aag/?display_name=tag)](https://github.com/reednel/aag/releases) [![GitHub license](https://img.shields.io/github/license/reednel/aag)](https://github.com/reednel/aag/blob/main/LICENCE) [![GitHub Issues](https://img.shields.io/github/issues/reednel/aag)](https://github.com/reednel/aag/issues) ![ ](https://img.shields.io/github/languages/code-size/reednel/aag)

## Description

A generic implementation of the AAG key exchange using the [SageMath](https://www.sagemath.org/) computer algebra system.

## Requirements

This program requires **Python** and **SAGE**. Sage may be installed in a Docker container as described in the next section.

## Docker Deployment

The `.devcontainer` folder contains the config to open this repository into a
Docker container with VS code and the [VS code Dev Containers
extension](https://code.visualstudio.com/docs/devcontainers/containers)
The `.devcontainer` folder contains the config to open this repository into a Docker container with VS code and the [VS code Dev Containers extension](https://code.visualstudio.com/docs/devcontainers/containers)

The Docker container comes with [SAGE](https://www.sagemath.org/) installed.

## Compiled code
See [this documentation](https://doc.sagemath.org/html/en/tutorial/programming.html) for more details on the importance of creating compiled code for execution speed.

## Usage

When the environment is configured inside a Docker container, a python file `file.py` can be run from its directory with `sage --python file.py`.

## Simulations in the Manuscript

All scripts and instructions to reproduce the analyses in the manuscript can be found in the `simulations` folder.

## Contributions, Questions, Issues, and Feedback

Users interested in expanding functionalities in MiNAA are welcome to do so. Issues reports are encouraged through Github's [issue tracker](https://github.com/reednel/aag/issues). See details on how to contribute and report issues in [CONTRIBUTING.md](https://github.com/reednel/aag/blob/master/CONTRIBUTING.md).

## License

See [this documentation](https://doc.sagemath.org/html/en/tutorial/programming.html) for more details on the importance of creating compiled code for execution speed.
MiNAA is licensed under the [MIT](https://opensource.org/licenses/MIT) licence.
37 changes: 20 additions & 17 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
from sage.groups.perm_gps.cubegroup import CubeGroup
from sage.groups.braid import BraidGroup

from aag import AAGExchangeObject
from attack import bruteforce
from src.aag import AAGExchangeObject
from src.attack import bruteforce

import random
import time

def test(group_type, group_object, pk_length, sk_length):

# EXCHANGE #

# Set up exchange objects (fixing the platform)
alice = AAGExchangeObject[group_type](group_object)
bob = AAGExchangeObject[group_type](group_object)
Expand All @@ -22,11 +24,9 @@ def test(group_type, group_object, pk_length, sk_length):
# Choose public keys
alice.generatePublicKey(pk_length)
bob.generatePublicKey(pk_length)

# Choose private keys
alice.generatePrivateKey(sk_length)
bob.generatePrivateKey(sk_length)

# Derive shared keys
aliceSharedKey = alice.deriveSharedKey(True, bob)
bobSharedKey = bob.deriveSharedKey(False, alice)
Expand All @@ -35,10 +35,18 @@ def test(group_type, group_object, pk_length, sk_length):
exchangeTime = (endExchangeTime - startExchangeTime) / 1000000 # to ms
print("Exchange Time:", exchangeTime)

# Attack
# ATTACK #

atb = alice.transition(bob)
bta = bob.transition(alice)
bfSharedKey = bruteforce(alice.publicKey, bob.publicKey, sk_length, atb, bta)

startAttackTime = time.time_ns()

bfSharedKey, guesses = bruteforce(alice.publicKey, bob.publicKey, sk_length, atb, bta)

endAttackTime = time.time_ns()
attackTime = (endAttackTime - startAttackTime) / 1000000 # to ms
print("Attack Time:", attackTime)

return (aliceSharedKey == bobSharedKey == bfSharedKey == alice.oracle(bob))

Expand All @@ -49,36 +57,31 @@ def main() -> int:
# return test(HeisenbergGroup, hg, 3, 3)

# PERMUTATION GROUP
# Note: a Permutation group with generators of the form (1 2),(1 3),...,(1 n) is the Symmetric group S_n
# PERMSIZE = 16
# Sn = [[(0, i)] for i in range(PERMSIZE)]
# pg = PermutationGroup(Sn)
# return test(PermutationGroup, pg, 10, 5)
PERMSIZE = 16
Sn = [[(0, i)] for i in range(PERMSIZE)]
pg = PermutationGroup(Sn)
return test(PermutationGroup, pg, 10, 4)

# # RUBIK'S CUBE GROUP
# rg = CubeGroup()
# test(CubeGroup, rg, 10, 10)
# test(CubeGroup, rg, 3, 4)

# # BRAID GROUP
# BRAIDSIZE = 5
# strands = ["s" + str(i) for i in range(BRAIDSIZE)]
# bg = BraidGroup(names=strands)
# return test(BraidGroup, bg, 3, 3)

pass


if __name__ == "__main__":
tests = 5
successes = [0 for _ in range(tests)]
for i in range(tests):
print(f"\n---------- ITERATION {i} (random seed = {i}) ----------")
print(f"\n---------- ITERATION {i} ----------")
random.seed(i)
success = main()
successes[i] = success

print("\n---------- RESULTS ----------")
for i, success in enumerate(successes):
print(f"Seed {i}: {'pass' if success else 'fail'}")

print(f"Success rate: {sum(successes) / len(successes) * 100}%")
12 changes: 6 additions & 6 deletions present.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from sage.groups.perm_gps.cubegroup import CubeGroup
from sage.groups.braid import BraidGroup

from aag import AAGExchangeObject
from src.aag import AAGExchangeObject

import itertools
import random
Expand Down Expand Up @@ -127,7 +127,7 @@ def animate(group_type, group_object, pk_length, sk_length):

backward_foxsay("""I compute my transition for you, because you
cannot see my secret key\n(A^-1*b*A) ∀ b ∈ b_bar""")

pause()
os.system('clear')
print(f"Ka = \n{aliceSharedKey}")
Expand Down Expand Up @@ -160,12 +160,12 @@ def animate(group_type, group_object, pk_length, sk_length):
print(f"Ka = \n{aliceSharedKey}")
print(f"Kb = \n{bobSharedKey}")
print("----------------------------------------------------------------------------------------------------")

pause()
os.system('clear')
cowsay.trex("I still know neither private key, so to obtain the shared key I would have to guess both private keys!")
pause()

print("\nTime:", elapsed)

return (aliceSharedKey == bobSharedKey and aliceSharedKey == alice.oracle(bob))
Expand All @@ -187,7 +187,7 @@ def demo_without_animation(group_type, group_object, pk_length, sk_length):
# derive shared key
aliceSharedKey = alice.deriveSharedKey(True, bob)
bobSharedKey = bob.deriveSharedKey(False, alice)

endTime = time.time()

os.system('clear')
Expand Down Expand Up @@ -225,7 +225,7 @@ def main():

hg_result = animate(HeisenbergGroup, hg, 27, 17)
successes.append(hg_result)

# PERMUTATION GROUP
pg = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]]) # ,[(5,6,7),(8,9)]
successes.append(demo_without_animation(PermutationGroup, pg, 23, 13))
Expand Down
2 changes: 1 addition & 1 deletion simulations/fix-cardinality.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import sys
sys.path.append('..')
from compare import generate
from src.compare import generate

# Warning: these parameters may require multiple days to complete.
def main():
Expand Down
2 changes: 1 addition & 1 deletion simulations/many-sims.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import sys
sys.path.append('..')
from compare import generate
from src.compare import generate

# Warning: these parameters may require multiple days to complete.
def main():
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions compare.py → src/compare.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aag import AAGExchangeObject
from attack import bruteforce
from src.aag import AAGExchangeObject
from src.attack import bruteforce
import csv
import time
from tqdm import tqdm
Expand Down Expand Up @@ -42,7 +42,6 @@ def timing(group_type, group_object, pk_length, sk_length):

return exchangeTime, attackTime, guesses


def generate(file_name, group_type, group, group_name, number_of_points, public_sizes, private_sizes):
with open(file_name, 'a', newline='') as f:
writer = csv.writer(f)
Expand Down

0 comments on commit 00501ad

Please sign in to comment.