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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
| program Codage_mdp;
{$mode objfpc}{$H+}
uses {$IFDEF UNIX} {$IFDEF UseCThreads}
cthreads, {$ENDIF} {$ENDIF}
Classes { you can add units after this };
type
Tab = array [1..36, 1..36] of char; //tableau pour le codage des mdp alphanumériques
Tab2 = array [1..10] of string[6]; //tableau des clés à coder
Tab3 = array [1..36,1..2] of char; //tableau pour le codage des mdp numériques
//Procedure pour initialiser le tableau de codage des mdp alphanumeriques
Procedure init_tab_alphanum(var tableau: tab);
var i,j:integer;
tempo:char;
begin
FOR i := 1 TO 36 DO
begin
IF (i < 27) THEN
tableau[1, i] := chr(64 + i)
ELSE
tableau[1, i] := chr(21 + i);
end;
FOR i := 2 TO 36 DO
begin
tempo := tableau[i - 1, 36];
FOR j := 1 TO 36 DO
begin
IF (j < 36) THEN
tableau[i, j + 1] := tableau[i - 1, j]
ELSE
tableau[i, 1] := tempo;
end;
end;
end;
//Procedure pour initialiser le tableau de codage des mdp numériques
Procedure init_tab_num (var tableau: tab3);
var i,m:integer;
begin
FOR i:=1 TO 26 DO tableau[i,1]:=chr(65+i-1);
FOR i:=1 TO 10 DO tableau[i+26,1]:=chr(48+i-1);
m:=48;
FOR i:=1 TO 36 DO
BEGIN
tableau[i,2]:=chr(m);
m:=m+1;
if m=58 then m:=48;
END;
end;
//Fonction pour trouver la référence croisée entre les 2 clés
//Elle renvoie un caractère
function recherche(cle1, cle2: char; tableau: tab): char;
var
i, a, b: integer;
begin
i := 1;
while cle1 <> tableau[1, i] do
begin
i := i + 1;
end;
a := i;
i := 1;
while cle2 <> tableau[i, 1] do
begin
i := i + 1;
end;
b := i;
recherche := tableau[b,a];
end;
//Fonction pour générer le mdp alphanumérique
//Elle renvoie une chaine de caractère
function mdp(cle: string; test: string; tableau: tab): string;
var
i, j,k: integer;
caract: char;
NumOk:boolean;
begin
//On génère le mdp
mdp:='';
FOR i := 1 TO 6 DO
begin
caract := recherche(cle[i], test[i], tableau);
mdp := concat(mdp + caract);
end;
//On vérifie qu'il y a bien 1 chiffre dans le mot de passe
//S'il n'y en a pas on insert un O à la fin
NumOk:=FALSE;
FOR k:=1 TO 6 DO
begin
j := 47;
WHILE ((mdp[k]<>chr(j)) AND (j<58) ) DO j:=j+1;
IF j<58 THEN NumOk:=TRUE;
end;
IF NOT NumOk THEN mdp[6]:='0';
end;
//Fonction pour générer les mdp numériques
//Elle renvoie une chaine de caractère
function nombre(tableau:tab3;cle:string):string;
var i,j:integer;
x:STRING[4];
begin
FOR i:=1 to 4 do
begin
j:=1;
begin
while cle[i]<>tableau[j,1] do j:=j+1;
x[i]:=tableau[j,2];
nombre:=x;
end;
end;
end;
var
TabChar: Tab;
TabChar2: Tab3;
TabMdp: Tab2;
i, lprim: integer;
caract, continu: char;
primaire: string;
secondaire, tertiaire: string[8];
admini, princi, exploi, consul, groupe, automa: string[6];
groupen,exploin:string[4];
begin
init_tab_alphanum (tabchar);
init_tab_num (tabchar2);
Write('SAISIR LA CLE PRIMAIRE (EN MAJUSCULE): ');
READLN(primaire);
repeat
begin
Write('SAISIR LA CLE SECONDIRE (EN MAJUSCULE): ');
READLN(secondaire);
lprim := length(primaire);
if lprim < 8 then
begin
primaire := concat(primaire + primaire);
lprim := length(primaire);
end;
for i := 8 downto 1 do
begin
caract := recherche(primaire[i], secondaire[i], tabchar);
tertiaire := concat(tertiaire + caract);
end;
tabmdp[1] := 'ADMINI';
tabmdp[2] := 'PRINCI';
tabmdp[3] := 'EXPLOI';
tabmdp[4] := 'CONSUL';
tabmdp[5] := 'GROUPE';
tabmdp[6] := 'AUTOMA';
admini := mdp(tertiaire, tabmdp[1], tabchar);
princi := mdp(tertiaire, tabmdp[2], tabchar);
exploi := mdp(tertiaire, tabmdp[3], tabchar);
consul := mdp(tertiaire, tabmdp[4], tabchar);
groupe := mdp(tertiaire, tabmdp[5], tabchar);
automa := mdp(tertiaire, tabmdp[6], tabchar);
groupen:=nombre(tabchar2,groupe);
exploin:=nombre(tabchar2,exploi);
WRITELN;
WRITELN(primaire,' ',secondaire,' ',tertiaire);
WRITELN;
WRITELN('Softools Administrateur: ', admini);
WRITELN('Softools Principal: ', princi);
WRITELN('Softools Exploitant: ', exploi);
WRITELN('Softools Consultant: ', consul);
WRITELN('Softools Groupe: ', groupe);
WRITELN('Softools automatisme: ', automa);
WRITELN;
WRITELN('SOFREL GROUPE: ',groupen);
WRITELN('SOFREL EXPLOI: ',exploin);
WRITELN;
WRITE('Generer une nouvelle cle? (non:N)');
READLN(continu);
end;
until (continu='N');
end. |
Partager