using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper5.Skyscraper.Text.Encodings
{
    [SkyscraperEncoding("dvb-iso-10646")]
    class dvb_iso_10646 : SkyscraperBaseEncoding16
    {
        protected override char[] Decrypt(byte[] preprocessed)
        {
            if (preprocessed.Length % 2 != 0)
                throw new ArgumentException("length must be divisible by 2");

            if (BitConverter.IsLittleEndian)
                for (int i = 0; i < preprocessed.Length; i += 2)
                    (preprocessed[i], preprocessed[i + 1]) = (preprocessed[i + 1], preprocessed[i]);

            Encoding utf16 = Encoding.GetEncoding("UTF-16");
            string result = utf16.GetString(preprocessed);
            return result.ToCharArray();
        }
    }
}
