Password

[b][red]This message was edited by Shadow1 at 2005-9-29 4:5:17[/red][/b][hr]
hi im currently writing a program that creates a password and encrypts it. i have this sussed but with my other programm thats ment to decrypt it. it isnt working i want to be able to create a password and store it in a text file and use a second program to read from the file decrypt the text and check if the text is correct to the inputted password ill include both program codes below if any 1 can help me direct where im going wrong ill be very greatfull

thanks shadow1

1st program that creats password

program password;
uses crt;

const null= '';
var i: integer;
ch:char;
origphrase, codedphrase: string[80];

function TRANSLATE (ch:char):char;
var loc: integer;
alphabet, key:string[26];
begin
alphabet:= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
key:= 'JVKM9LON8IBHDCREFZU1PYG7XASQ2WTjvkml3onibhdc4r0efzup5y6gxasqwt';
loc:= pos (ch, alphabet);
if loc > 0 then translate:= key[loc]
else translate:= ch
end;

begin
write ('type a password ');
readln (origphrase);
codedphrase:=null;
for i := 1 to length (origphrase) do
begin
ch:=origphrase[i];
codedphrase:=codedphrase+translate (ch)
end;

writeln (codedphrase)
end.


2nd (program that is ment to decode and check)

program enter;

uses crt;
var
c: char;
pas: string;

const null= '';
var i: integer;
passfile: text ;
ch:char;
origphrase, codedphrase: string[80];
function TRANSLATE (ch:char):char;
var loc: integer;
alphabet, key:string[62];

begin

alphabet:= 'JVKM9LON8IBHDCREFZU1PYG7XASQ2WTjvkml3onibhdc4r0efzup5y6gxasqwt';
key:= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ';
loc:= pos (ch, alphabet);
if loc > 0 then translate:= key[loc]
else translate:= ch
end;
begin

clrscr;
writeln ('please enter password');
repeat
c:=readkey;
if c<>#13 then pas:=pas+c; {add the character to the password}
write('*');
until c=#13;

assign (passfile, 'a:pass.txt');
reset (passfile);
while not eof (passfile) do
begin
readln (passfile, pas);
writeln (pas);
end;

close (passfile);



Comments

  • : [b][red]This message was edited by Shadow1 at 2005-9-29 4:5:17[/red][/b][hr]
    : hi im currently writing a program that creates a password and encrypts it. i have this sussed but with my other programm thats ment to decrypt it. it isnt working i want to be able to create a password and store it in a text file and use a second program to read from the file decrypt the text and check if the text is correct to the inputted password ill include both program codes below if any 1 can help me direct where im going wrong ill be very greatfull
    :
    : thanks shadow1
    :
    : 1st program that creats password
    :
    [code]
    : program password;
    : uses crt;
    :
    : const null= '';
    : var i: integer;
    : ch:char;
    : origphrase, codedphrase: string[80];
    :
    : function TRANSLATE (ch:char):char;
    : var loc: integer;
    : alphabet, key:string[26];
    : begin
    : alphabet:= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    : key:= 'JVKM9LON8IBHDCREFZU1PYG7XASQ2WTjvkml3onibhdc4r0efzup5y6gxasqwt';
    : loc:= pos (ch, alphabet);
    : if loc > 0 then translate:= key[loc]
    : else translate:= ch
    : end;
    :
    : begin
    : write ('type a password ');
    : readln (origphrase);
    : codedphrase:=null;
    : for i := 1 to length (origphrase) do
    : begin
    : ch:=origphrase[i];
    : codedphrase:=codedphrase+translate (ch)
    : end;
    :
    : writeln (codedphrase)
    : end.
    [/code]
    :
    :
    : 2nd (program that is ment to decode and check)
    :
    [code]
    : program enter;
    :
    : uses crt;
    : var
    : c: char;
    : pas: string;
    :
    : const null= '';
    : var i: integer;
    : passfile: text ;
    : ch:char;
    : origphrase, codedphrase: string[80];
    : function TRANSLATE (ch:char):char;
    : var loc: integer;
    : alphabet, key:string[62];
    :
    : begin
    :
    : alphabet:= 'JVKM9LON8IBHDCREFZU1PYG7XASQ2WTjvkml3onibhdc4r0efzup5y6gxasqwt';
    : key:= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ';
    : loc:= pos (ch, alphabet);
    : if loc > 0 then translate:= key[loc]
    : else translate:= ch
    : end;
    : begin
    :
    : clrscr;
    : writeln ('please enter password');
    : repeat
    : c:=readkey;
    : if c<>#13 then pas:=pas+c; {add the character to the password}
    : write('*');
    : until c=#13;
    :
    : assign (passfile, 'a:pass.txt');
    : reset (passfile);
    : while not eof (passfile) do
    : begin
    : readln (passfile, pas);
    : writeln (pas);
    : end;
    :
    : close (passfile);
    [/code]
    I can see the Translate() function, but it isn't called in the program Enter. Neither does that program perform any check wether the password is correct or not.
  • : : [b][red]This message was edited by Shadow1 at 2005-9-29 4:5:17[/red][/b][hr]
    : : hi im currently writing a program that creates a password and encrypts it. i have this sussed but with my other programm thats ment to decrypt it. it isnt working i want to be able to create a password and store it in a text file and use a second program to read from the file decrypt the text and check if the text is correct to the inputted password ill include both program codes below if any 1 can help me direct where im going wrong ill be very greatfull
    : :
    : : thanks shadow1
    : :
    : : 1st program that creats password
    : :
    : [code]
    : : program password;
    : : uses crt;
    : :
    : : const null= '';
    : : var i: integer;
    : : ch:char;
    : : origphrase, codedphrase: string[80];
    : :
    : : function TRANSLATE (ch:char):char;
    : : var loc: integer;
    : : alphabet, key:string[26];
    : : begin
    : : alphabet:= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    : : key:= 'JVKM9LON8IBHDCREFZU1PYG7XASQ2WTjvkml3onibhdc4r0efzup5y6gxasqwt';
    : : loc:= pos (ch, alphabet);
    : : if loc > 0 then translate:= key[loc]
    : : else translate:= ch
    : : end;
    : :
    : : begin
    : : write ('type a password ');
    : : readln (origphrase);
    : : codedphrase:=null;
    : : for i := 1 to length (origphrase) do
    : : begin
    : : ch:=origphrase[i];
    : : codedphrase:=codedphrase+translate (ch)
    : : end;
    : :
    : : writeln (codedphrase)
    : : end.
    : [/code]
    : :
    : :
    : : 2nd (program that is ment to decode and check)
    : :
    : [code]
    : : program enter;
    : :
    : : uses crt;
    : : var
    : : c: char;
    : : pas: string;
    : :
    : : const null= '';
    : : var i: integer;
    : : passfile: text ;
    : : ch:char;
    : : origphrase, codedphrase: string[80];
    : : function TRANSLATE (ch:char):char;
    : : var loc: integer;
    : : alphabet, key:string[62];
    : :
    : : begin
    : :
    : : alphabet:= 'JVKM9LON8IBHDCREFZU1PYG7XASQ2WTjvkml3onibhdc4r0efzup5y6gxasqwt';
    : : key:= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ';
    : : loc:= pos (ch, alphabet);
    : : if loc > 0 then translate:= key[loc]
    : : else translate:= ch
    : : end;
    : : begin
    : :
    : : clrscr;
    : : writeln ('please enter password');
    : : repeat
    : : c:=readkey;
    : : if c<>#13 then pas:=pas+c; {add the character to the password}
    : : write('*');
    : : until c=#13;
    : :
    : : assign (passfile, 'a:pass.txt');
    : : reset (passfile);
    : : while not eof (passfile) do
    : : begin
    : : readln (passfile, pas);
    : : writeln (pas);
    : : end;
    : :
    : : close (passfile);
    : [/code]
    : I can see the Translate() function, but it isn't called in the program Enter. Neither does that program perform any check wether the password is correct or not.
    :


    Instead of trying to decrypt the password file and checking the plain text against plain text, try checking the cypher text against the cyphertext in the file, so just encrypt the text again and check it with the entry in the file. That will be much easier
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories