class Util
  {
    private const int PWD_DATA_SIZE = 40;
    public static byte[] getPWD(string pwd)
    {
      //PWD_HS1:  IDC_HS1:;
      byte[] bpwd = new byte[PWD_DATA_SIZE];
      byte[] head = Encoding.ASCII.GetBytes("PWD_HS1:");
      byte[] spwd = Encoding.ASCII.GetBytes(pwd);
      byte[] temp = new byte[32 - spwd.Length];
      byte[] mpwd = MergerArray(spwd, temp);
      temp = new byte[32];
      Util.FKHS3760_EncryptPwd(ref mpwd, ref temp, 32);
      bpwd = MergerArray(head, temp);
      return bpwd;
    }    public static byte[] MergerArray(byte[] First, byte[] Second)
    {
      byte[] result = new byte[First.Length + Second.Length];
      First.CopyTo(result, 0);
      Second.CopyTo(result, First.Length);
      return result;
    }    public static void FKHS3760_EncryptPwd(ref byte[] apOrgPwdData, ref byte[] apEncPwdData, int aPwdLen)
    {
      int i;      gPassEncryptKey = 12415;
      for (i = 0; i < aPwdLen; i++)
        apEncPwdData[i] = Encrypt_1Byte(apOrgPwdData[i]);
    }    public static int gPassEncryptKey;
     public static byte Encrypt_1Byte(byte aByteData)
     {
       int U0 = 28904;
       int U1 = 35756;
       byte vCrytData;       vCrytData = (byte)(aByteData ^ (byte)(gPassEncryptKey >> 8));
       gPassEncryptKey = (vCrytData + gPassEncryptKey) * U0 + U1;
       return vCrytData;
     }     public static void FKHS3760_DecryptPwd(byte[] apEncPwdData,ref byte[] apOrgPwdData, int aPwdLen)
     {
       int i;       gPassEncryptKey = 12415;
       for (i = 0; i < aPwdLen; i++)
         apOrgPwdData[i] = Decrypt_1Byte(apEncPwdData[i]);
     }     public static byte Decrypt_1Byte(byte aByteData)
     {
       int U0 = 28904;
       int U1 = 35756;
       byte vCrytData;       vCrytData = (byte)(aByteData ^ (byte)(gPassEncryptKey >> 8));
       gPassEncryptKey = (aByteData + gPassEncryptKey) * U0 + U1;
       return vCrytData;
     }
  }