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 :: python vrer un fichier texte 
Python :: python else 
Python :: how to make an argument optional in python 
Python :: pandas transform vs filter 
Python :: django values_list 
Python :: how to watermark a video using python 
Python :: csv.dictreader 
Python :: Finding the maximum element from a matrix with Python numpy.argmax() 
Python :: activate venv in python 
Python :: dataframe cut 
Python :: swap case python 
Python :: odd number in python 
Python :: mro in python 
Python :: stringindexer pyspark 
Python :: python os check if file with extension exists 
Python :: Python Tkinter ListBox Widget Syntax 
Python :: printing hello world in python 
Python :: reverse linked list python 
Python :: python suppress print output from function 
Python :: numpy nditer 
Python :: class views django slug 
Python :: pandas get number unique values in column 
Python :: hur många partier sitter i riksdagen 
Python :: how to add percentages to ylabel python 
Python :: how to make a time limit using renpy 
Python :: is cobol obsolete 
Python :: rapids - convert nerworkx to cugraph 
Shell :: linux check if x11 
Shell :: postgres stop linux 
Shell :: gyp ERR! stack Error: not found: make 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =