Click to See Complete Forum and Search --> : Delphi to CSharp


FTremonti
October 3rd, 2009, 08:50 AM
Hello,

I wold like to export this code( Delphi ) to C#

Can Help me?

Código:
function CryptAlgorithm(cString: String): String;
var
nStringLen, nCharCount: Integer;
nInterim, nChar: Byte;
cChar: Char;
begin
nStringLen := length( cString );

if nStringLen = 0 then begin
nKey := 0;
nSalt := 0;
end
else begin
for nCharCount := 0 to nStringLen - 1 do begin
cChar := cString[ nCharCount+1 ];

{ only encipher printable characters }
if (( cChar >= ' ' ) and ( cChar <= '~' )) then begin
nkey := ( nkey and $1FFFFFFF ) xor (( nkey shr 29 ) and $00000031 );
nChar := Byte( cChar );
nInterim := Mod95(( nKey div 95 ) - ( nChar - 32 )) + 32;
nSalt := nSalt + 1;

if ( nSalt >= 20857 ) then begin
nSalt := 0;
end;

nKey := nKey + nKey + ( nInterim xor nChar ) + nSalt;

cString[ nCharCount+1 ] := Char( nInterim );
end;
end;
end;
Result := cString;
end;


function Mod95( nVal : Integer ): Integer;
begin
Result := nVal;

while ( Result >= 9500 ) do begin
Result := Result - 9500;
end;

while ( Result >= 950 ) do begin
Result := Result - 950;
end;

while ( Result >= 95 ) do begin
Result := Result - 95;
end;

while ( Result < 0 ) do begin
Result := Result + 95;
end;
end;

dglienna
October 3rd, 2009, 12:37 PM
Google found a few: https://www.turnsharp.com/try-it.aspx