示例#1
0
        public void Crypt(string key, string plaintext)
        {
            var keyBytes       = ByteHelper.HexToByteArray(key);
            var plaintextBytes = Encoding.ASCII.GetBytes(plaintext);
            var cypher         = new byte[plaintextBytes.Length];

            if (keyBytes.Length < plaintext.Length)
            {
                return;
            }

            for (int i = 0; i < plaintextBytes.Length; i++)
            {
                var bitKey       = ByteHelper.ConvertByteToBoolArray(keyBytes[i]);
                var bitPlaintext = ByteHelper.ConvertByteToBoolArray(plaintextBytes[i]);
                var cypherbits   = new bool[8];
                for (int j = 0; j < 8; j++)
                {
                    cypherbits[j] = XOR(bitKey[j], bitPlaintext[j]);
                    // cypherbits[j] = XOR(bitKey[j], cypherbits[j]);
                }
                cypher[i] = ByteHelper.ConvertBoolArrayToByte(cypherbits);
            }
            CypherPrintableBytes = ByteHelper.ByteArrayToHex(cypher);
        }
示例#2
0
        public void Decrypt(string key, string crypt)
        {
            var keyBytes       = ByteHelper.HexToByteArray(key);
            var cryptBytes     = ByteHelper.HexToByteArray(crypt);
            var plaintextBytes = new byte[cryptBytes.Length];

            if (keyBytes.Length < cryptBytes.Length)
            {
                return;
            }

            for (int i = 0; i < cryptBytes.Length; i++)
            {
                var bitKey    = ByteHelper.ConvertByteToBoolArray(keyBytes[i]);
                var bitCrypt  = ByteHelper.ConvertByteToBoolArray(cryptBytes[i]);
                var plainText = new bool[8];
                for (int j = 0; j < 8; j++)
                {
                    plainText[j] = XOR(bitKey[j], bitCrypt[j]);
                }
                plaintextBytes[i] = ByteHelper.ConvertBoolArrayToByte(plainText);
            }
            Message = Encoding.ASCII.GetString(plaintextBytes);
        }
示例#3
0
 public AKRule(byte value)
 {
     _value = ByteHelper.ConvertByteToBoolArray(value);
 }