Giter Club home page Giter Club logo

basic-rsa's Introduction

Basic RSA implementation

Encryption

1.Choose two different primes p and q.

2.Our modulus(n) will be n=p*q.

3.Calculate t = (p-1)*(q-1)

4.Now we have to choose e (public key exponent) such that 1<e<t and gcd(e,t)=1 .But it is advisable to choose a medium range e becuase if e is very large or very small than RSA can be attacked using various techniques.

5.Then we have to compte d (private key) such that d*e=1+kt where k is a natural number.

Now we have all the things ready to encrypt.

Let the message be m.

Put ciphertext (c) = power(m,e) % n
{pow(m,e,n) can be used in python}

Now our ciphertext is ready !!! :)

Decryption

Coming Soon !!!!

CODE

from Crypto.Util.number import *
import random
from fractions import gcd
print("Enter text to encrypt")
inp=input()
p=getPrime(32)
q= getPrime(32)
n=p*q
t=(p-1)*(q-1)
while(True):
	e=random.randint(1,65537)
	if(gcd(e,t)==1):
		break
for k in range(t):
	d=(1+(k*t))/e
	if(float(d).is_integer()==True):
		break
d=int(d)
m=inp.encode('utf=8')
m=m.hex()
m=int(m,16)
c=pow(m,e,n)

You can get the python code for encyption here.

Decryption of RSA Coming Soon !!

basic-rsa's People

Contributors

d4rkvaibhav avatar

Stargazers

 avatar

Watchers

 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.