示例#1
0
        public static Word SubWord(this Word word)
        {
            var bytes = new List <Entities.Byte>();

            for (var i = 0; i < word.Value.Length; i++)
            {
                var replacedByte = new Entities.Byte(SBoxHelper.GetReplacement(word.Value[i].Value));
                bytes.Add(replacedByte);
            }

            return(new Word(bytes.ToArray()));
        }
示例#2
0
        public static Word Shift(this Word word)
        {
            var bytesArray = word.Value;

            AES.Entities.Byte[] resultArray = new AES.Entities.Byte[bytesArray.Length];
            for (int i = 0; i < bytesArray.Length; i++)
            {
                if (i < bytesArray.Length - 1)
                {
                    resultArray[i] = bytesArray[i + 1];
                }
                else
                {
                    resultArray[i] = bytesArray[0];
                }
            }

            return(new Word(resultArray));
        }
示例#3
0
        public static List <Word> ExtractWords(this string plainText)
        {
            var words = new List <Word>();

            for (var i = 0; i < plainText.Length; i += WordStringLength)
            {
                var wordString = plainText.Substring(i, Math.Min(WordStringLength, plainText.Length - i));
                var bytes      = new List <AES.Entities.Byte>();
                for (var j = 0; j < wordString.Length; j += ByteStringLength)
                {
                    var byteString = wordString.Substring(j, Math.Min(ByteStringLength, wordString.Length - j));
                    var _byte      = new AES.Entities.Byte(byteString);
                    bytes.Add(_byte);
                }

                words.Add(new Word(bytes.ToArray()));
            }

            return(words);
        }
示例#4
0
 public static Entities.Byte Xor(this Entities.Byte _byte, Entities.Byte other)
 {
     return(new Entities.Byte(_byte.Value ^ other.Value));
 }