///////// Ce Compte-Rendu a été réalisé par
Bauer Jérémy
Balesdent Mathieu
N1B promo 49
ISEN Lille //////////>
Pour ouvrir le programme Maple
permettant de crypter et de décrypter un message codé avec le système RSA
cliquez sur le lien suivant : > restart; > message:=bonjour; Les nombres p et q doivent absolument être premier > if isprime(P)=true
then print("P est premier") else print("P n'est pas
premier")fi; Détermination de E > LE:=[]: Cryptage
du message Vérification des conditions > if isprime(Q)=true
and Assignation des lettres > (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,_):=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27): Cryptage > lg:=length(message): ] Décryptage
du message Désassignation
des lettres > (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,_):=('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_'): Détermination
de la clé d > D1:=op(2,op(msolve(E*D=1,(P-1)*(Q-1)))); Décryptage > L2:=[]: ] Réassignation > (Z[1],Z[2],Z[3],Z[4],Z[5],Z[6],Z[7],Z[8],Z[9],Z[10],Z[11],Z[12],Z[13],Z[14],Z[15],Z[16],Z[17],Z[18],Z[19],Z[20],Z[21],Z[22],Z[23],Z[24],Z[25],Z[26],Z[27]):=(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,_): Lecture
du message décrypté
> mess1:=NULL: Outils
Maple Trouver
un nombre premier entre n et p (n et p 2 réels) > Premier:=[]: ] Pour
trouver facilement un nombre premier Trouver
les facteurs premiers d'un réel R (2) (3)² (13)
Menu
Message, clés
secrètes : p et q et clés publiques : n et e
P:=nextprime(997):
Q:=nextprime(2371):
N:=P*Q;
N
if isprime(Q)=true then print("Q est premier") else print("Q
n'est pas premier") fi;
Q est premier
for EE from 1 to P while nops(LE)<5 do
if igcd(EE,(P-1)*(Q-1))= 1 then LE:=[op(LE),EE] else "E n'est pas premier
avec p-1 et q-1"
fi:
od;
LE;
E:=LE[2];
E
isprime(P)=true and
igcd(E,(P-1)(Q-1))= 1
then "cryptage possible"
else "une condition n'est pas remplie"
fi;
L0:=[]:
L1:=[]:
L10:=[]:
L11:=[a]:
nombre[0]:=0:
S:=1:
mess[0]:=message:
# les lettres sont associées 2 à 2 avant d'être cryptées
if type(message,integer)=true
then
L11:=[nombre]:
for kl from 1 to lg
do nombre[kl]:=trunc(mess[kl-1]/10^(lg-S));
mess[kl]:=(mess[kl-1]-nombre[kl]*10^(lg-S));
S:=S+1;
od;
for R from 1 to lg
do L10:=[op(L10),nombre[R]]:
L11:=[op(L11),modp((nombre[R])^E,N)]:
od:
print("nombre non crypté" =L10);
print("nombre crypté" =L11);
else
for R from 1 to lg
do Lettre[R]:=substring(message,R)
od;
if N > 2727
then
if type(lg/2,integer)=true
then
else Lettre[lg+1]:=Lettre[lg]:
Lettre[lg]:=0:
lg:=lg+1
fi:
for R from 1 to lg/2
do L0:=[op(L0),Lettre[2*R]+100*Lettre[2*R-1]]:
L1:=[op(L1),modp((Lettre[2*R]+100*Lettre[2*R-1])^E,N)]:
od:
else
for R from 1 to lg
do L0:=[op(L0),Lettre[R]]:
L1:=[op(L1),modp((Lettre[R])^E,N)]:
od:
fi;
print("message non crypté" =L0);
print("message crypté" =L1);
fi:
message crypté
facD:=ifactor(D1);
for JK from 1 to nops(facD) do
if nops(op(JK,facD))=2
then CléD[JK]:=op(op(1,op(1,facD)))^op(2,op(1,facD));
else
CléD[JK]:=op(op(JK,facD))
fi;
od;
L3:=[]:
L12:=[]: #pour les chiffres
L13:=[nomb]:
if op(1,L11)=nombre
then
opL:=nops(L11):
for R from 2 to opL
do ME[R]:=modp(op(R,L11)^D1,N);
od:
L13:=[nombre,seq(ME[Rt],Rt=2..opL)];
print(L13);
else
opL:=nops(L1):
opL1:=nops(ifactor(D1));
opF:=ifactor(D1);
for R from 1 to opL
do ME[R]:=modp(op(R,L1)^(op(op(1,opF))),N);
for RL from 2 to opL1 do
ME[R]:=modp(ME[R]^(op(op(RL,opF))),N);
od:
od:
if N>2727
then
L2:=[seq([Z[trunc(ME[RT]/100)],Z[ME[RT]-trunc(ME[RT]/100)*100]],RT=1..opL)];
L3:=[seq(op(L2[ER]),ER=1..opL)]:
if L3[2*opL-1]=Z[0]
then L3[2*opL-1]:=op(2*opL,L3);
opL:=opL-1/2
else
fi;
else L3:=[seq(Z[ME[Rt]],Rt=1..opL)]
fi;
print(L2);
print(L3);
print("message décrypté");
fi:
mess2:=NULL:
if op(1,L13)=nombre
then
for S from 2 to opL
do
mess1:=cat(mess1,L13[S])
od:
print("message"=mess1);
else
if N>2727
then opL:=2*opL
else
fi:
for S from 1 to opL
do
mess1:=cat(mess1,L3[S])
od:
print("message"=mess1);
fi:
for N from 340 to 350
do
if isprime(N)=true
then Premier:=[op(Premier),N]
else
fi:
od:
Premier;
> npremier:=nextprime(34567);
isprime(npremier);
ifactor(234);