Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Password Posted by Shadow1 on 29 Sept 2005 at 3:57 AM
This message was edited by Shadow1 at 2005-9-29 4:5:17

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);



Report
Re: Password Posted by zibadian on 29 Sept 2005 at 4:18 AM
: This message was edited by Shadow1 at 2005-9-29 4:5:17

: 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);

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.
Report
Re: Password Posted by DavidAimes on 10 Oct 2005 at 12:21 PM
: : This message was edited by Shadow1 at 2005-9-29 4:5:17

: : 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);
: 

: 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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.