Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python rsa

import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random

random_generator = Random.new().read
key = RSA.generate(1024, random_generator) #generate public and private keys

publickey = key.publickey # pub key export for exchange

encrypted = publickey.encrypt('encrypt this message', 32)
#message to encrypt is in the above line 'encrypt this message'

print 'encrypted message:', encrypted #ciphertext

f = open ('encryption.txt', 'w'w)
f.write(str(encrypted)) #write ciphertext to file
f.close()

#decrypted code below

f = open ('encryption.txt', 'r')
message = f.read()

decrypted = key.decrypt(message)

print 'decrypted', decrypted

f = open ('encryption.txt', 'w')
f.write(str(message))
f.write(str(decrypted))
f.close()
Comment

python rsa

>>> import rsa
>>> (bob_pub, bob_priv) = rsa.newkeys(512)
Comment

RSA with python

#Par Mouad En-nasiry
dic1={chr(i+96):i for i in range (1,27)}
dic1['+'],dic1['-']=27,28

def get_key(dic,val):
    for key, value in dic.items():
         if val == value:
                return key
            #trouver la cle d'un valuer
def exp(A, P):
    #on a suppose que A>=1 P>=0
    result = 1
    while P >= 1:
        result = result * A
        P -= 1
    return result #touver la puissance rapidement

def Mod(A, P, M):
    return exp(A,P)%29  # donner le rest de la division euclidienne de A**P Par 29



def chiffrer(M):
    Code = str()
    for i in M.lower():
        X=Mod(dic1[i],17,29)
        Code+=get_key(dic1,X)
    return Code.upper()

def decrypter(C):
    Message = str()
    for i in C.lower():
        X=Mod(dic1[i],5,29)
        Message+=get_key(dic1,X)
    return Message.upper()

Msg=input('pour chiffrer Entrez 1 pour Decrypter Entrez 2:')

if Msg=='1':
    Msg=input('entrer le message: ')
    print(chiffrer(Msg))
elif Msg=='2':
    Msg=input('entrer le message codé: ')
    print(decrypter(Msg))
Comment

PREVIOUS NEXT
Code Example
Python :: django link home page 
Python :: how to shutdown a windows 10 computer using python 
Python :: plot histogram python 
Python :: install from github 
Python :: python screen click 
Python :: python getting class name 
Python :: python day of the week 
Python :: pandas add two string columns 
Python :: python float precision 
Python :: jupyter lab 
Python :: install pip with pacman linux 
Python :: how to check if file exists pyuthon 
Python :: python files 
Python :: equal sides of an array python 
Python :: tuple slicing in python 
Python :: dictionary python length 
Python :: sklearn train_test_split 
Python :: python program for printing fibonacci numbers 
Python :: python undefine variable 
Python :: Python Tkinter timer animation 
Python :: select certain element from ndarray python 
Python :: raising exceptions in python 
Python :: ipython.display install 
Python :: create 2d array python list comprehension 
Python :: count rows with nan pandas 
Python :: How to convert simple string in to camel case in python 
Python :: python - iterate with the data frame 
Python :: how to change the background of heading in tkinter 
Python :: python try then change something and try again if fails 
Python :: python cut string after character 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =