private string fCrypt( string Action, string Key, string Src)
{
int vKeyLen = Key . Length;
int vKeyPos = 0 ;
byte [] vKeyBuffer = Encoding . UTF8 . GetBytes(Key);
if (Action == "E" )
{
byte [] vSrcBuffer = Encoding . UTF8 . GetBytes(Src);
string vReturn = "" ;
Random vRandom = new Random ();
byte vOffset = ( byte )vRandom . Next( 256 );
vReturn = vOffset . ToString( "X2" );
foreach ( byte vByte in vSrcBuffer)
{
byte vTemp = ( byte )((vByte + vOffset) % 255 );
vTemp ^= vKeyBuffer[vKeyPos];
vKeyPos = (vKeyPos + 1 ) % vKeyLen;
vReturn += vTemp . ToString( "X2" );
vOffset = vTemp;
}
return vReturn;
}
else if (Action == "D" )
{
byte [] vDest = new byte [(Src . Length - 2 ) / 2 ];
int vOffset = int . Parse(Src . Substring( 0 , 2 ),
System . Globalization . NumberStyles . HexNumber);
for ( int i = 2 ; i < Src . Length; i += 2 )
{
byte vByte = ( byte ) int . Parse(Src . Substring(i, 2 ),
System . Globalization . NumberStyles . HexNumber);
byte vTemp = ( byte )(vByte ^ vKeyBuffer[vKeyPos]);
if (vTemp <= vOffset)
vTemp = ( byte )( 255 + vTemp - vOffset);
else vTemp -= ( byte )vOffset;
vKeyPos = (vKeyPos + 1 ) % vKeyLen;
vDest[i / 2 - 1 ] = vTemp;
vOffset = vByte;
}
return Encoding . UTF8 . GetString(vDest);
}
return null ;
}