Problem with encryption - Programmers Heaven

Howdy, Stranger!

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


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem with encryption

koupas991koupas991 Posts: 1Member
I am new to pascal.I need to make a program that read a whole text and a line of letters which will replace the alphabet.My problem is that i don't know how to read the text and keep every single letter.

while not eoln do

this is what i use.aba is where i place the letters. it does'nt start and it says:command terminated by signal 24


  • AtexAtex Posts: 268Member
    Here's a simple single file encryption/decryption program using a simple xor encryption method. The beauty of this is that the same code does the job both ways.[code][color=Blue]{ Compiler TP/BP7 }

    {$M 16384,0,655360}

    var f_in,f_out:file; { Files as untyped }
    f_in_name,f_out_name,pwd:string;{ File names }
    pwd_value,bytes_read:word; { Password checksum, read counter }
    i:word; { Counter }
    buffer:array[0..16383] of byte; { 16 kByte buffer for data }

    pwd_value:=0; { Init password checksum with 0 }
    write('Enter filename to encrypt/decrypt: ');readln(f_in_name);
    write('Enter filename to decrypt/encrypt: ');readln(f_out_name);
    write('Enter password: ');readln(pwd);
    for i:=1 to length(pwd) do begin { Calculate BSD checksum of the password }
    pwd_value:=(pwd_value shr 1) + ((pwd_value and 1) shl 15); { Parity bit }
    inc(pwd_value,ord(pwd[i])); { Increment password checksum }
    pwd_value:=pwd_value and $ffff; { Keep it whitin bounds }
    randseed:=pwd_value; { Init random seed with password checksum }
    assign(f_in,f_in_name);reset(f_in,1); { Open input file for read }
    if ioresult<>0 then begin { Check if input file exists }
    writeln(f_in_name,' not found, exiting.');
    assign(f_out,f_out_name);rewrite(f_out,1);{ Create output file }
    while not(eof(f_in)) do begin
    blockread(f_in,buffer,16384,bytes_read); { Read a chunk for input file }
    for i:=1 to bytes_read do { Encrypt or Decrypt (Same thing) }
    buffer[i]:=buffer[i] xor byte(random(256));{ Simple XOR encryption }
    blockwrite(f_out,buffer,bytes_read); { Output encrypted/decrypted data }
    close(f_in);close(f_out); { Close both files }
Sign In or Register to comment.