espero esto te ayude ,
program mqenigma;
uses
crt;
const
teclado : array[1..26] of char = {Teclado}
'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
RI : array[1..2, 1..26] of char = {Rueda I}
('ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'EKMFLGDQVZNTOWYHXUSPAIBRCJ');
RII : array[1..2,1..26] of char = {Rueda II}
('ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'AJDKSIRUXBLHWTMCQGZNPYFVOE');
RIII : array[1..2,1..26] of char = {Rueda III}
('ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'BDFHJLCPRTXVZNYEIWGAKMUSQO');
espejo : array[1..2,1..26] of char = {Espejo}
('FSURTZOXJGHYBINACVLKQWDMPE',
'SFCBZTMJXLDARPKYUWGNEVHOIQ');
pasoIIIaII : array[1..2,1..26] of char = {Conesiones Rueda III a II}
('CEGIKBOQSWUYMXDHVFZJLTRPNA',
'DFHJLCPRTXVZNYEIWGAKMUSQOB');
pasoIIaI : array[1..2,1..26] of char = {Conesiones Rueda II a I}
('DSRXLJMQZFPOWVKUYIEBHNGCTA',
'DSRXLJMQZFPOWVKUYIEBHNGCTA');
pasoIaespejo : array[1..2,1..26] of char = {Conesiones Rueda I a Espejo}
('FSURTZOXJGHYBNACVLKQWDMPE',
'FSURTZOXJGHYBNACVLKQWDMPE');
type
letras = array[1..2,1..26] of char;
var
leer : letras;
contador, cont, yp : integer;
tecla : char;
pasa : boolean;
codifi : char;
textoariginal, textoclave : string;
claveinc : array[1..3] of char;
procedure pasaletra(cual : integer; leer : letras);
var
pas, i : integer;
let1, let2 : char;
begin
case cual of
1 : begin
let1 := RI[1][1];
let2 := RI[2][1];
end;
2 : begin
let1 := RII[1][1];
let2 := RII[2][1];
end;
3 : begin
let1 := RIII[1][1];
let2 := RIII[2][1];
end;
end;
for i := 1 to 26 do
begin
case cual of
1 : begin
leer[1][i] := RI[1][i + 1];
leer[2][i] := RI[2][i + 1];
end;
2 : begin
leer[1][i] := RII[1][i + 1];
leer[2][i] := RII[2][i + 1];
end;
3 : begin
leer[1][i] := RIII[1][i + 1];
leer[2][i] := RIII[2][i + 1];
end;
end;
end;
case cual of
1 : begin
leer[1][26] := let1;
leer[2][26] := let2;
end;
2 : begin
leer[1][26] := let1;
leer[2][26] := let2;
end;
3 : begin
leer[1][26] := let1;
leer[2][26] := let2;
end;
end;
for i := 1 to 26 do
begin
case cual of
1 : begin
rI[1][i] := leer[1][i];
rI[2][i] := leer[2][i];
end;
2 : begin
rII[1][i] := leer[1][i];
rII[2][i] := leer[2][i];
end;
3 : begin
rIII[1][i] := leer[1][i];
rIII[2][i] := leer[2][i];
end;
end;
end;
end;
procedure ponclaveinicio;
var
tec : char;
ni : integer;
begin
claveinc[1] := 'A';
claveinc[2] := 'A';
claveinc[3] := 'A';
gotoxy(10,10);write('**** CLAVE INICIO ****');
gotoxy(10,12);write('I = ',claveinc[1],' II = ',claveinc[2],' III = ',claveinc[3]);
gotoxy(10,14);write('DESEA MODIFICAR CLAVES [S/N] ');
repeat
tec := readkey;
until tec in['n','N','s','S'];
if tec in ['s','S'] then
begin
clrscr;
gotoxy(1,1);write('Pasar III = Tecla Numero [3] ');
gotoxy(1,3);write('Pasar II = Tecla Numero [2] ');
gotoxy(1,5);write('Pasar I = Tecla Numero [1] ');
for ni := 1 to 26 do
begin
gotoxy(20,10 + (ni + 1));write(rI[1][ni]);
gotoxy(24,10 + (ni + 1));write(rII[1][ni]);
gotoxy(28,10 + (ni + 1));write(rIII[1][ni]);
end;
repeat
tec := readkey;
if tec in [#49,#50,#51] then
begin
case tec of
#49 : begin
pasaletra(1,leer);
end;
#50 : begin
pasaletra(2,leer);
end;
#51 : begin
pasaletra(3,leer);
end;
end;
end;
for ni := 1 to 26 do
begin
gotoxy(20,10 + (ni + 1));write(rI[1][ni]);
gotoxy(24,10 + (ni + 1));write(rII[1][ni]);
gotoxy(28,10 + (ni + 1));write(rIII[1][ni]);
end;
until (tec = #13) or (tec = #27);
end;
clrscr;
end;
procedure presenta_estructuras(cual : integer);
begin
case cual of
1 : begin
gotoxy(59,2);write('III');
end;
2 : begin
gotoxy(55,2);write('II');
end;
3 : begin
gotoxy(52,2);write('I');
end;
end;
textcolor(15);
case cual of
1 : begin
gotoxy(52, 4);write(rI[1][1]);
end;
2 : begin
gotoxy(56, 4);write(rII[1][1]);
end;
3 : begin
gotoxy(60, 4);write(rIII[1][1]);
end;
end;
textcolor(15);
end;
function enciendeletra(letra : char) : char;
var
d1, d2 : integer;
con1, con2 : char;
encontra : boolean;
begin
d1 := 1;
encontra := false;
repeat
if rIII[1][d1] = letra then
begin
encontra := true;
con1 := rIII[2][d1];
for d2 := 1 to 26 do
if con1 = pasoIIIaII[1][d2] then
con2 := pasoIIIaII[2][d2];
for d2 := 1 to 26 do
if con2 = rII[1][d2] then
con1 := rII[2][d2];
for d2 := 1 to 26 do
if con1 = pasoIIaI[1][d2] then
con2 := pasoIIaI[2][d2];
for d2 := 1 to 26 do
if con2 = pasoIaespejo[1][d2] then
con1 := pasoIaespejo[2][d2];
for d2 := 1 to 26 do
if con1 = espejo[1][d2] then
con2 := espejo[2][d2];
end;
d1 := d1 + 1;
until (encontra = true) or (d1 > 26);
if encontra = true then
begin
encontra := false;
enciendeletra := con2;
end;
end;
procedure pantalla;
begin
textcolor(15);
gotoxy(50,1);write('ÚÄÄÄÂÄÄÄÂÄÄÄ¿');
gotoxy(50,2);write('³ ³ ³ ³');
gotoxy(50,3);write('ÃÄÄÄÅÄÄÄÅÄÄÄ´');
gotoxy(50,4);write('³ ³ ³ ³');
gotoxy(50,5);write('ÀÄÄÄÁÄÄÄÁÄÄÄÙ');
for yp := 1 to 26 do
begin
gotoxy(30 + (yp + 8),34);write(teclado[yp]);
end;
presenta_estructuras(1);
presenta_estructuras(2);
presenta_estructuras(3);
end;
procedure claveinicio;
var
clv1, clv2, clv3 : char;
co : integer;
begin
clv1 := RI[1][1];
clv2 := RII[1][1];
clv3 := RIII[1][1];
gotoxy(40,40);write('Clave Inicio = ',clv1,'-',clv2,'-',clv3);
end;
procedure iluminaletra(cu : char);
var
hi : integer;
begin
hi := 1;
textcolor(15);
gotoxy(20,44);write('LUCES');
repeat
if teclado[hi] = cu then
begin
textcolor(5);
end;
gotoxy(10 + hi,46);write(teclado[hi]);
textcolor(15);
hi := hi + 1;
until hi > 26;
end;
begin
clrscr;
ponclaveinicio;
pantalla;
cont := 1;
yp := 3;
contador := 1;
claveinicio;
iluminaletra(' ');
gotoxy(2 + cont,yp);
repeat
tecla := readkey;
if upcase(tecla) in[#65..#90] then
begin
textcolor(14);
gotoxy(2 + cont,yp);write(upcase(tecla));
textoariginal[cont] := upcase(tecla);
textoariginal[0] := chr(cont);
cont := cont + 1;
if cont > 34 then
begin
yp := yp + 1;
cont := 1;
end;
codifi := enciendeletra(upcase(tecla));
textoclave[contador] := codifi;
textoclave[0] := chr(contador);
iluminaletra(codifi);
contador := contador + 1;
textcolor(15);
pasaletra(3,leer);
presenta_estructuras(3);
gotoxy(2 + cont,yp);
if rIII[1][1] = 'V' then
begin
pasa := true;
pasaletra(2,leer);
presenta_estructuras(2);
gotoxy(2 + cont,yp);
end;
if (rII[1][1] = 'E') and (pasa = true) then
begin
pasa := false;
pasaletra(1,leer);
presenta_estructuras(1);
gotoxy(2 + cont,yp);
end;
end;
gotoxy(2 + cont,yp);
until (tecla = #27) or (tecla = #13);
clrscr;
gotoxy(30,20);write('TEXTO REAL : ',textoariginal);
gotoxy(30,22);write('CODIFICADO : ',textoclave);
gotoxy(20,24);write('*** PULSA UNA TECLA PARA SALIR ***');
repeat until keypressed;
end.