Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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))
Source by stuvel.eu #
 
PREVIOUS NEXT
Tagged: #RSA #python
ADD COMMENT
Topic
Name
2+7 =