Click to See Complete Forum and Search --> : Delphi to VB Conversion Help


December 7th, 1999, 11:42 AM
I need these two functions converted to VB...
Can someone help, please???

function Decrypt(const S: String; Key: Word): String;
var
I: byte;
begin
SetLength(Result,Length(S));
for I := 1 to Length(S) do
begin
Result[i] := char(byte(S[i]) xor (Key shr 8));
Key := (byte(S[i]) + Key) * C1 + C2;
end;
end;


function Encrypt(const S: String; Key: Word): String;
var
I: byte;
begin
SetLength(Result,Length(S));
for I := 1 to Length(S) do
begin
Result[i] := char(byte(S[i]) xor (Key shr 8));
Key := (byte(Result[i]) + Key) * C1 + C2;
end;
end;

AndyK
December 8th, 1999, 12:20 AM
I'm not sure if this is exactly word for word, but I hope you will get the basic of encrypting/decrypting:

private Function Decrypt(byval SEnc as string)
for I = 1 to len(SEnc)
Str = mid(SEnc, I, 1)
mid(SEnc, I, 1) = Chr(Asc(Str) - 1)
next
Decrypt = SEnc
End Function




private Function Encrypt(byval S as string)
for I = 1 to len(S)
Str= mid(S, I, 1)
mid(S, I, 1) = Chr(Asc(Str) + 1)
next
Encrypt = S
End Function

December 8th, 1999, 09:09 AM
I'm afraid that would not do what I'm looking for.
I need to be able to use the same table in both
applications so the strings MUST be identical when
encrypted by EITHER the Delphi program or the VB
program.

Thanks for trying...

AndyK
December 8th, 1999, 04:01 PM
You can make a textbox and use Encrypt and Decrypt functions to get the string from that that textbox....

December 9th, 1999, 10:38 AM
What the hell are you talking about? I already have the text boxes and I want to encrypt/decrypt the values in those text boxes as well as values in the
fields of a table.

I just want the algorithm I posted converted to VB so I can use the SAME DATA
in BOTH APPLICATIONS!!!!!

Ravi Kiran
December 10th, 1999, 03:57 AM
I DOnt know Delphi.. and i use to know (?) Pascal!. So what is shr : "Shift right" is what i guessed. But then shift right 8 times with or w/o carry (meaning loop back or not)? What are C1 and C2?

RK