We help IT Professionals succeed at work.

How to encrypt and descrypt txt file

shekou
shekou asked
on
I have a txt format file and don't like user to use Notepad to view it, how to encrypt it and descrypt it?


Thanks

Shekou
Comment
Watch Question

Mohammed NasmanSoftware Developer
CERTIFIED EXPERT

Commented:
look at this link, you can download component to help you to do that
http://www.torry.net/cryptstrong.htm

Commented:
There are diffrent way's to do i. the most smple one is to do an xor "encryption" you encrypt byte per byte with eg. 56.. now the file is encrypted to decrypt it xor with  56 again and the original text will appear.

look for this on the web

blowfish
des


this will lead to manny good sites..

happy hunting!

Commented:
Hello Shekou,

there are many encyption methods

please visite this site:
http://www.efg2.com/Lab/Library/Delphi/MathFunctions/Cryptography.htm

Best Regards

Cesario

Commented:
This works fine for both cryptin and decrypting

procedure Scrample(var fin, fout : Text);
var
  ch : char;
begin
  randseed := 12345;  // Your code;
  While not eof(fin) do begin
    read(fin,ch);
    ch := char(random(256) xor byte(ch));
    write(fout,ch);
  end;
end;

You have to open and close the files self !

Olle K
Commented:
I made a simple function that takes a line as input and encrypts it or decrypts it.

function MyIncrypt(Fcode: Boolean; FTextIn : string): string;
var MyChar   : char;
    MyString : String;
    i , key  : integer;
begin
  Result := '';
  key := length(FTextIn);

  if FCode then //Encrypt
  begin
    for i := 1 to key do
    begin
      MyString  := copy(FTextIn, i, 1);
      MyChar := char( Ord(MyString[1]) + key + i + FKeyValue mod   256);
      Result := Result + chr(Ord(MyChar))
    end;
  end else //Decrypt
  begin
    for i := 1 to key do
    begin
      MyString  := copy(FTextIn, i, 1);
      MyChar := char( Ord(MyString[1]) - key - i - FKeyValue mod   256);
      Result := Result + chr(Ord(MyChar))
    end;
  end;
end;

Marcel (Holland)

Author

Commented:
Work great!

Thanks

Shekou

Explore More ContentExplore courses, solutions, and other research materials related to this topic.