I have a project at school in which I have decieded to make an encryption system which I am struggling with quite a bit at the moment - just finding resources to use and even a guide to follow.
The only half decent thing i can find on the web is the code that I will put at the bottom of the post.
Can someone point me in the right direction to a guide or just something to help me get started? If that is not possible, I would be so grateful if someone could possibly write a short but detailed description of what it going on in the below code.
Thanks so much if you can help!
{ Compiler TP/BP7 }
{$A+,B-,D-,E-,F-,G+,I-,L-,N+,O-,P-,Q-,R-,S-,T-,V-,X+}
{$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 }
begin
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 }
end;
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.');
halt;
end;
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 }
end;
close(f_in);close(f_out); { Close both files }
end.