GithubHelp home page GithubHelp logo

notgnoshi / cryptography Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 1.08 MB

Coursework for CSC 512, Cryptography

Python 77.96% TeX 20.18% MATLAB 1.04% Makefile 0.83%
cryptography number-theory linear-algebra python-library coursework homework portfolio python abstract-algebra

cryptography's Introduction

Cryptography

Coursework for CSC 512, Cryptography.


About

This repository consists of the coursework for my CSC 512 Cryptography class at SDSM&T. It is split into two pieces:

The homework/ folder is, unsurprisingly, my homework for the course. The crypto/ folder is my class portfolio of cryptography-related code. It is implemented as a Python module providing a number of different logical submodules.

Dependencies

The crypto library has the following dependencies:

  • Python 3.6+
  • gmpy2 which has its own dependencies:
    • libgmp3-dev
    • libmpc-dev
    • libmpfr-dev
  • numpy
  • concurrencytest (optional, but recommended)
  • sympy

The dependencies may be installed on Ubuntu as follows:

  • Install python3.6 and pip:
    # Add Python3.6 apt repository if using 16.04 LTS
    sudo add-apt-repository ppa:jonathonf/python-3.6  # (only for 16.04 LTS)
    sudo apt update
    # Install Python 3.6
    sudo apt install python3.6
    sudo apt install python3.6-dev
    sudo apt install python3.6-venv
    # Install an up-to-date version of Pip
    wget https://bootstrap.pypa.io/get-pip.py
    sudo python3.6 get-pip.py
    
    # Use Python 3.6 as the default Python3
    sudo ln -s /usr/bin/python3.6 /usr/local/bin/python3
    sudo ln -s /usr/local/bin/pip /usr/local/bin/pip3
    
    # Verify installation
    python --version
    python3 --version
    $(head -1 `which pip` | tail -c +3) --version
    $(head -1 `which pip3` | tail -c +3) --version
  • Install gmpy2
    # Install dependencies for pip to compile gmpy2
    sudo apt install libgmp3-dev libmpc-dev libmpfr-dev
    # Might have to use pip3 depending on the output of $(head -1 `which pip` | tail -c +3) --version
    sudo -H pip install --upgrade gmpy2
  • Install other Python dependencies:
    sudo -H pip install --upgrade numpy sympy concurrencytest

Documentation

Example usage may be found in the course homework and in the unit tests. Run pydoc3 -b and navigate to the crypto link to view the crypto library documentation.

Unit tests

The unit tests may be ran by any of the following:

$ python3 runtests.py
$ ./runtests.py
$ python3.6 runtests.py

Note that sometimes the test script hangs while waiting for a lock to release due to the tests being run concurrently. If this happens, send a KeyboardInterrupt and try again.


Usage:

  • Download the repository and create a test.py script to test code in:

    ~ $ git clone https://github.com/Notgnoshi/cryptography.git
    ~ $ cd cryptography
    ~/cryptography/ $ echo '#!/usr/bin/env python3' >> test.py
    ~/cryptography/ $ chmod +x test.py
  • Inside test.py the crypto library may be used like so:

    • Running the unit tests with a given number of processes
      #!/usr/bin/env python3
      from crypto.tests import runtests
      # Requires the concurrencytest library installed. Will run in serial otherwise
      runtests(processes=8)
    • Some bitwise utilities
      #!/usr/bin/env python3
      from crypto.utilities import Bitstream, lazy_pad, bits_to_string
      
      # One of many forms a bytestream can take
      bytestream = b'This is a test'
      # Lazily pad the bytestream so that it's length is evenly divisible by 8
      # The pad values will be randomly chosen from the given array
      bytestream = lazy_pad(bytestream, multiple=8, pad_values=b'abcdefghijklmnopqrstuvwxyz')
      # Construct a Bitstream
      bitstream = Bitstream(bytestream)
      
      # Hopefully unchanged
      output = bits_to_string(bitstream)
      print(output)
      # Will be `This is a test` with two random characters appended
    • Some classical ciphers
      #!/usr/bin/env python3
      from crypto.classical import AffineCipher, LfsrCipher
      import numpy
      
      plaintext = 'affine'
      cipher = AffineCipher(9, 2)
      ciphertext = cipher.encrypt(plaintext)
      assert ciphertext == 'cvvwpm'
      
      # Values taken from HW 1 problem 6
      initial_values = numpy.array([1, 0, 1, 0, 0, 1])
      coeffs = numpy.array([1, 1, 0, 1, 1, 0])
      cipher = LfsrCipher(initial_values, coeffs)
      
      ciphertext = cipher.encrypt('zyxwvuts')
      ciphertext = [ord(c) for c in ciphertext]
      expected = [31, 90, 153, 215, 233, 255, 13, 164]
      assert ciphertext == expected

cryptography's People

Contributors

notgnoshi avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.