예제 #1
0
        internal static string DecodeFileName(Span <byte> encodedName)
        {
            for (int i = 0; i < encodedName.Length; i++)
            {
                // swap nibbles
                encodedName[i] = (byte)((encodedName[i] & 0x0F) << 4 | (encodedName[i] & 0xF0) >> 4);
            }

            for (int i = 0; i < encodedName.Length / DataEncryptionStandard.BlockSize; i++)
            {
                DataEncryptionStandard.DecryptBlock(encodedName.Slice(
                                                        i * DataEncryptionStandard.BlockSize,
                                                        DataEncryptionStandard.BlockSize));
            }

            var fileName = string.Empty;

            for (int i = 0; i < encodedName.Length; i++)
            {
                if ((char)encodedName[i] == 0)
                {
                    break;
                }

                fileName += (char)encodedName[i];
            }

            return(fileName);
        }
예제 #2
0
        private static void DecodeHeader(Span <byte> data)
        {
            int blocks = data.Length / DataEncryptionStandard.BlockSize;

            // first 20 blocks are DES-encrypted
            for (int i = 0; i < 20 && i < blocks; ++i)
            {
                DataEncryptionStandard.DecryptBlock(data.Slice(i * DataEncryptionStandard.BlockSize, DataEncryptionStandard.BlockSize));
            }
        }
예제 #3
0
        private static void DecodeFull(Span <byte> source, uint compressedSize)
        {
            DecodeHeader(source);

            int blocks = source.Length / DataEncryptionStandard.BlockSize;
            int digits = compressedSize.ToString().Length;

            int gapBetweenEncryptedBlocks = (digits < 3) ? 1
                   : (digits < 5) ? digits + 1
                   : (digits < 7) ? digits + 9
                   : digits + 15;
            int gapBetweenShuffledBlocks = 7;

            int j = -1;

            for (int i = 20; i < blocks; ++i)
            {
                if ((i % gapBetweenEncryptedBlocks) == 0)
                {
                    // DES-encrypted
                    DataEncryptionStandard.DecryptBlock(
                        source.Slice(
                            i * DataEncryptionStandard.BlockSize,
                            DataEncryptionStandard.BlockSize));

                    continue;
                }

                ++j;
                if ((j % gapBetweenShuffledBlocks) == 0 && j != 0)
                {
                    DeshuffleBlock(
                        source.Slice(
                            i * DataEncryptionStandard.BlockSize,
                            DataEncryptionStandard.BlockSize));

                    continue;
                }
            }
        }