コード例 #1
0
ファイル: BlowfishContext.cs プロジェクト: synfron/FiSH
        /// <summary>
        /// After being initialized with a key, the schedule (p-array) and s-boxes needs some
        /// work from the Blowfish engine to finish setting up.
        /// </summary>
        void Setup()
        {
            // The setup process starts with the all zero string.
            UInt64 bitScape = 0;

            // To set up the schedule (p-arrays),
            for (int i = 0; i < 9; i++)
            {
                bitScape = BlowfishEngine.Encrypt(ByteOperations.Swap(bitScape), this);
                Schedule.Set(i * 2, ByteOperations.Left(bitScape));
                Schedule.Set(i * 2 + 1, ByteOperations.Right(bitScape));
                bitScape = ByteOperations.Swap(bitScape);
            }

            // To finish the s-boxes
            for (int i = 0; i < 1024;)
            {
                bitScape = BlowfishEngine.Encrypt(ByteOperations.Swap(bitScape), this);

                sbox[i / 256, i % 256] = ByteOperations.Left(bitScape);
                i++;
                sbox[i / 256, i % 256] = ByteOperations.Right(bitScape);
                i++;

                bitScape = ByteOperations.Swap(bitScape);
            }
        }