Git Product home page Git Product logo

knapsack's Introduction

Knapsack

A simple (yet functional) PKC algorithm based on Knapsack

This work is my first approach into the PKC world. This implementation intends to be a light-weight public-key cryptosystem based on the subset sum problem (a special case of the knapsack problem) which is known to be NP-Complete.

KeyGen

  • Choose a superincreasing sequence with enough elements (notice that implementations of this algorithm are no longer considered secure nowadays. So you must choose a Knapsack at least with 250 elements and these must be within the range of 200 to 400bits to be used in practice). The following superincreasing sequence will be our private key.

Knapsack1

  • Pick random integers m, n such that:

Knapsack2

  • Calculate public key by computing the following to every element on the knapsack.

βi = n*xi mod p

Kp = {β1, β2, ... , βi} - computed values above will be the public key

Cipher

To cipher a message with k bits, just compute the following and represent the correspondent integers.

Knapsack3

An example. For the message 011010110101 the process will look like this.

Knapsack4

Our ciphered message is {276,280}

Decipher

In order to decipher a ciphertext c a receiver has to find the message bits αi such that they satisfy:

Knapsack5

This would be a hard problem if the βi were random values because the receiver would have to solve an instance of the subset sum problem, which is known to be NP-hard. However, the values βi were chosen such that decryption is easy if the private key is known. Given that, we only need to find an integer s that is the modular inverse of n mod m (Extended Euclidean algorithm).

Then the receiver of the ciphertext c computes:

Knapsack6

Taking the same example presented before, the process will look like this where the modular inverse of n is 61.

Knapsack7

Now the receiver only has to solve the subset sum problem (which is easy because the knapsack is a superincreasing sequence).

Knapsack8

Finally, the last step of our example will look like this. Notice that original message was recovered.

Knapsack9

knapsack's People

Contributors

celioggr avatar

Watchers

 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.