Giter Club home page Giter Club logo

ellipticcurves's Introduction

import matplotlib.pyplot as plt

%matplotlib inline
plt.rcParams['figure.figsize'] = (10.0, 5.0)

from ecc import *
# Curve Parameters
a = 7
b = 3
field_size = 37

ecc = EllipticCurve(a, b, field_size)
ecc.plot_curve()
<module 'matplotlib.pyplot' from 'c:\\python34\\lib\\site-packages\\matplotlib\\pyplot.py'>

png

# Define a Generator
Generator = Point(ecc, 2, 5, "Generator")
# Plotting points on the curve
ecc.plot_points([Generator])

png

# Multiply points by a scalar and plot. You can give names to the point too. 
# Addition of points in the field has also been implemented

G2 = Generator * 2
G2.name = "2 * Generator"
print(G2)
ecc.plot_points([G2])
Point 2 * Generator = (17, 22)

png

# Explaining the Diffie Hellman Key exchange
# Assume key exchange between Alice and Bob.

alice_private_key = 4
bob_private_key = 7
# The public key for Bob and Alice are defined by multiplying the Generator with their Private Keys

# Alice 
alice_pub = alice_private_key * Generator
alice_pub.name = "Alice Public Key"

print(alice_pub)
Point Alice Public Key = (7, 32)
# Bob
bob_pub = bob_private_key * Generator
bob_pub.name = "Bob Public Key"

print(bob_pub)
Point Bob Public Key = (18, 35)
# Let us see where these points are on our curve - 

ecc.plot_points([Generator, alice_pub, bob_pub])

png

# The above points and the curves are available publicly. 
# Thus, the shared secret is calculated by multiplying the public keys of the reciever with youur own private key.

shared_secret_bob = alice_pub * bob_private_key
shared_secret_alice = bob_pub * alice_private_key
# Let's check if these secrets generated independently are the same. 

print(shared_secret_alice)
print(shared_secret_bob)

# You can simply compare the two objects too! :D 
assert(shared_secret_alice == shared_secret_bob)
Point  = (22, 1)
Point  = (22, 1)
# Let's give it a name
shared_secret_alice.name = "Shared Secret"
# Let us see the public keys and the shared secret! 

ecc.plot_points([Generator, alice_pub, bob_pub, shared_secret_alice])

png

ellipticcurves's People

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.