Correction du problème bac 2014 Niveau : 4ieme année sciences & math Proposé pa

Correction du problème bac 2014 Niveau : 4ieme année sciences & math Proposé par: Bassem Amor Année scolaire: 2021/2022 cryptage lecture() crypter(msg) remplir(msg,t,n) Programme principal Verif(msg) dist(t,n,t1) cryptage lecture() crypter(msg) remplir(msg,t,n) Programme principal fonction fonction procedure Verif(msg) fonction dist(t,n,t1) procedure Algorithme du programme principal : Algorithme cryptage Début msg ← lecture() s←crypter (msg) Écrire("Le message crypté est ",s) fin T.D.O.G objet type msg chaine s chaine lecture fonction crypter fonction Algorithme de la fonction lecture Fonction lecture () :chaine Début Répéter Ecrire ("taper le message : ") Lire(msg) Jusqu’à (verif(msg)et((pos (" ",msg)=-1)) Retourner(msg) fin T.D.O.L objet type msg chaine verif fonction Algorithme de la function verif fonction verif (ch : chaine) : booléen Début dep ← ".,;:!?" i ← 0 valide ← vrai tantque valide et (i<long(ch)) faire si(pos(ch[i],dep)≠ -1)alors valide ← faux sinon i ← i+1 finsi Fin tantque Retourner(valide) fin T.D.O.L objet type dep chaine i entier valide booléen Algorithme de la fonction crypter Fonction crypter (msg:chaine) :chaine Début Remplir(msg,T,i) dist(T,i,T1) ch ← "" Pour j de 0 à long(T[0]) faire ch ← ch+T1[j]+" " Fin pour ch ← effacer(ch,long(ch)-1,long(ch)) Retourner(ch) fin T.D.O.L objet type T,T1 Tab i,j entier ch chaine T.D.N.T type Tab=tableau de 50 chaines Algorithme de la procedure remplir Procedure remplir (msg:chaine;@T:tab;@i:entier) Début i←0 ch ←msg+“ " max ←0 Tantque (ch≠"") faire p ← pos(“ “,ch) T[i] ←souschaine(ch,0, p)) ch ←effacer(ch,0, p+1) i← i+1 si (p>max) alors max ←p finsi Fin tantque Pour j de 0 à (i-1) faire l ←long(T[j]) pour k de 1 à (max-l) faire T[j] ←T[j]+"*“ fin pour Fin pour fin T.D.O.L objet type p entier k entier j entier l entier ch chaine Algorithme de la procedure dist Procedure dist (t:tab;r:entier;@T1:tab) Début Pour k de 0 à r faire ch ←T[k] pour j de 0 à long(ch)-1 faire T1[j] ←T1[j]+ch[j] fin pour Fin pour fin T.D.O.L objet type k entier j entier ch chaine import numpy as np # module verif def verif(ch): dep=".,;:!?" i=0 valide=True while valide and(i<len(ch)): if(dep.find(ch[i])!=-1): valide=False else: i=i+1 return(valide) # module lecture def lecture(): ok=False while not(ok): msg=input("msg= ") ok=verif(msg)and(msg.find(' ')==-1) return msg # module remplir def remplir(t,msg): ch=msg+' ' max=0 i=0 while(ch!=''): p=ch.find(" ") t[i]=ch[:p] ch=ch[p+1:] i=i+1 if(p>max): max=p for j in range(i): l=len(t[j]) for k in range(1,max-l+1): t[j]=t[j]+'*' return (i) #module dist def dist (T,r,T1): for k in range(r): ch=T[k] for j in range(len(ch)): T1[j]=str(T1[j])+ch[j] # module crypter def crypter (msg): T=np.array(['']*20,dtype=(str,20)) i=remplir(T,msg) T1=np.array(['']*len(T[0]),dtype=(str,i)) dist(T,i,T1) ch = "" for j in range(len(T[0])): ch = ch+T1[j]+" " ch =ch[:len(ch)-1] return(ch) #le prog principal msg=lecture() s=crypter(msg) print(s) uploads/Litterature/ correction-bac2014.pdf

  • 24
  • 0
  • 0
Afficher les détails des licences
Licence et utilisation
Gratuit pour un usage personnel Attribution requise
Partager