function DecrypTText(Intext: string): string; var Buffer: array[0..8191] of byte; Hash: TDCP_sha1; HashDigest, HashRead: array[0..31] of byte; Decrypt: TDCP_blockcipher; // IDEA:TDCP_IDEA; Read: integer; tm, tx: tStringStream; begin result := ''; FillChar(HashDigest, Sizeof(HashDigest), $FF); // fill the digest with $FF as the actual digest may not fill the entire digest Hash := TDCP_sha1.Create(Application); Hash.Init; // hash the passphrase to get the key Hash.UpdateStr(HashPhrase); Hash.Final(HashDigest); Hash.Free; // IDEA:=TDCP_IDEA.create(Application); Decrypt := TDCP_blockcipher(Mainform.IDEA); // get the component from the combo box if (Sizeof(HashDigest) * 8) > Decrypt.MaxKeySize then Decrypt.Init(HashDigest, Decrypt.MaxKeySize, nil) // make sure the key isn't too big else Decrypt.Init(HashDigest, Sizeof(HashDigest) * 8, nil); // initialize the cipher with the digest, IV= nil to generate one automatically (note: size in bits ie. sizeof(x)*8) Decrypt.EncryptCBC(HashDigest, HashDigest, Sizeof(HashDigest)); // encrypt the hash to use as confirmation Decrypt.Reset; intext := uuencode(intext, false); tx := tstringStream.create(intext); tm := tstringStream.create(''); tx.seek(0, soFromBeginning); tx.read(HashRead, sizeof(hashread)); (* if not CompareMem(@HashRead,@HashDigest,Sizeof(HashRead)) then begin Decrypt.Burn; MessageDlg('Incorrect passphrase',mtInformation,[mbOK],0); tx.free; tm.free; Exit; end; *) tm.seek(0, soFromBeginning); repeat read := tx.read(buffer, sizeof(buffer)); Decrypt.DecryptCBC(Buffer, Buffer, Read); // read from the source decrypt and write out the result tm.Write(buffer, read); until Read <> Sizeof(Buffer); Decrypt.Burn; // IDEA.free; tx.free; result := tm.datastring; tm.free; end;
Write, Run & Share Pascal code online using OneCompiler’s Pascal online compiler for free. It’s a straightforward, accessible way to learn and experiment with Pascal programming right from your browser. OneCompiler supports modern Pascal syntax and provides a ready-to-use editor for immediate execution.
Pascal is a procedural programming language developed in the 1970s by Niklaus Wirth. It was designed to encourage good programming practices and structured programming. Pascal is widely used in teaching computer science fundamentals and has influenced many modern languages.
The following is a simple Pascal program that prints a greeting:
program HelloWorld;
begin
writeln('Hello, OneCompiler!');
end.
OneCompiler’s Pascal editor supports stdin through the I/O tab. Here’s an example that reads a user's name and prints a greeting:
program GreetUser;
var
name: string;
begin
readln(name);
writeln('Hello, ', name, '!');
end.
var
age: integer;
name: string;
score: real;
flag: boolean;
Type | Description |
---|---|
integer | Whole numbers |
real | Floating-point numbers |
char | Single character |
string | Sequence of characters |
boolean | True or False |
if score >= 50 then
writeln('Pass')
else
writeln('Fail');
for i := 1 to 5 do
writeln(i);
i := 1;
while i <= 5 do
begin
writeln(i);
i := i + 1;
end;
i := 1;
repeat
writeln(i);
i := i + 1;
until i > 5;
procedure SayHello;
begin
writeln('Hello!');
end;
function Add(a, b: integer): integer;
begin
Add := a + b;
end;
This guide provides a quick reference to Pascal programming syntax and features. Start coding in Pascal using OneCompiler’s Pascal online compiler today!