Skip to main content

Implements El Gamal scheme over Elliptic Curves for encryption. Overwrites Pythons inbuilt functions to allow modular arithmetic in finite fields and elliptic curve group operations by using the * symbol

Project description

This package was written for learning purposes only. It should not be used in any situation where real security is required.

I have implemented the El Gamal method of asymetric key exchnge over elliptic curves. The field, curve, and starting point used in this implementation came from http://www.secg.org/sec2-v2.pdf under the nickname 'secp256r1'. I used this curve and field because it provides an adequate level of security while remaining relatively fast. It is my understanding that fields any larger cannot be proccessed quickly due to current hardware design limitations. One way around this is by using a larger field for an initial asymetric key which would be used to communicate a symmetric key. This would seem to be a best of both worlds type approach but more research would be needed to be certain.

I chose three different classes/objects for this project. The first is modNum.The class of modNum is an integer number that can be manipulated by the usual math functions of +,-,*,/,//,**,+=,...,/= as well as it's own sqrt() function.

The second class is EllipticCurve. The EllipticCurve class has immutable class variables that define the field and curve to be used. Instantiating an instance of EllipticCurve takes two integers, x and y, and uses them to create two instances of the modNum class. The instantiation also confirms that the given x,y are valid points on the curve. This check is crucial since the field must be closed. This class also supercedes the built in functions for * and **. Multiplication becomes the elliptic curve group operation and ** powering using that group operation.

The third class is ElGamal. This class creates a random private key for each instance of the class and uses that private key to create a secondary public key, h. Using encrypt() you can encrypt any message by providing the prime and both public keys of the recipient of the message. Then using the specific instance ElGamal that generated the private key and secondary public key you can decrypt a message intended for for the create of that specifc instance. Obviously in a real application you would need to be able to store the private key. But I chose to not implement a method to do that since this code shouldn't be used in real applications.

I also wrote a full suite of tests for all exposed functions. I even wrote a specifc version of encrypt with a lower level of security to be used solely for testing purposes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ElGamalEllipticCurves-0.1.11.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

ElGamalEllipticCurves-0.1.11-py3-none-any.whl (10.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page