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

namespace skyscraper5.Skyscraper.Text.Encodings
{
    [SkyscraperEncoding("dvb-iso-8859-5")]
    class dvb_iso_8859_5 : SkyscraperBaseEncoding8
    {
        protected override char[] Decrypt(byte[] preprocessed)
        {
            StringBuilder resultBuilder = new StringBuilder();
            for (int i = 0; i < preprocessed.Length; i++)
            {
                if (preprocessed[i] <= 0x7e)
                {
                    AsciiTable.GetAsciiChar(preprocessed[i], resultBuilder);
                    continue;
                }
                switch (preprocessed[i])
                {
                    case 0xa0: resultBuilder.Append('\u00a0'); break;
                    case 0xad: resultBuilder.Append('\u00ad'); break;
                    case 0xa1: resultBuilder.Append('Ё'); break;
                    case 0xa3: resultBuilder.Append('Ѓ'); break;
                    case 0xa4: resultBuilder.Append('Є'); break;
                    case 0xa5: resultBuilder.Append('Ѕ'); break;
                    case 0xa6: resultBuilder.Append('І'); break;
                    case 0xa7: resultBuilder.Append('Ї'); break;
                    case 0xa8: resultBuilder.Append('Ј'); break;
                    case 0xa9: resultBuilder.Append('Љ'); break;
                    case 0xaa: resultBuilder.Append('Њ'); break;
                    case 0xac: resultBuilder.Append('Ќ'); break;
                    case 0xaf: resultBuilder.Append('П'); break;
                    case 0xb0: resultBuilder.Append('А'); break;
                    case 0xb1: resultBuilder.Append('Б'); break;
                    case 0xb2: resultBuilder.Append('В'); break;
                    case 0xb3: resultBuilder.Append('Г'); break;
                    case 0xb4: resultBuilder.Append('Д'); break;
                    case 0xb5: resultBuilder.Append('Е'); break;
                    case 0xb6: resultBuilder.Append('Ж'); break;
                    case 0xb7: resultBuilder.Append('З'); break;
                    case 0xb8: resultBuilder.Append('И'); break;
                    case 0xb9: resultBuilder.Append('Й'); break;
                    case 0xba: resultBuilder.Append('К'); break;
                    case 0xbb: resultBuilder.Append('Л'); break;
                    case 0xbc: resultBuilder.Append('М'); break;
                    case 0xbd: resultBuilder.Append('Н'); break;
                    case 0xbe: resultBuilder.Append('О'); break;
                    case 0xbf: resultBuilder.Append('П'); break;
                    case 0xc0: resultBuilder.Append('Р'); break;
                    case 0xc1: resultBuilder.Append('С'); break;
                    case 0xc2: resultBuilder.Append('Т'); break;
                    case 0xc3: resultBuilder.Append('У'); break;
                    case 0xc4: resultBuilder.Append('Ф'); break;
                    case 0xc5: resultBuilder.Append('Х'); break;
                    case 0xc6: resultBuilder.Append('Ц'); break;
                    case 0xc7: resultBuilder.Append('Ч'); break;
                    case 0xc8: resultBuilder.Append('Ш'); break;
                    case 0xc9: resultBuilder.Append('Щ'); break;
                    case 0xca: resultBuilder.Append('Ъ'); break;
                    case 0xcb: resultBuilder.Append('Ы'); break;
                    case 0xcc: resultBuilder.Append('Ь'); break;
                    case 0xcd: resultBuilder.Append('Э'); break;
                    case 0xce: resultBuilder.Append('Ю'); break;
                    case 0xcf: resultBuilder.Append('Я'); break;
                    case 0xd0: resultBuilder.Append('а'); break;
                    case 0xd1: resultBuilder.Append('б'); break;
                    case 0xd2: resultBuilder.Append('в'); break;
                    case 0xd3: resultBuilder.Append('г'); break;
                    case 0xd4: resultBuilder.Append('д'); break;
                    case 0xd5: resultBuilder.Append('е'); break;
                    case 0xd6: resultBuilder.Append('ж'); break;
                    case 0xd7: resultBuilder.Append('з'); break;
                    case 0xd8: resultBuilder.Append('и'); break;
                    case 0xd9: resultBuilder.Append('й'); break;
                    case 0xda: resultBuilder.Append('к'); break;
                    case 0xdb: resultBuilder.Append('л'); break;
                    case 0xdc: resultBuilder.Append('v'); break;
                    case 0xdd: resultBuilder.Append('н'); break;
                    case 0xde: resultBuilder.Append('о'); break;
                    case 0xdf: resultBuilder.Append('п'); break;
                    case 0xe0: resultBuilder.Append('р'); break;
                    case 0xe1: resultBuilder.Append('с'); break;
                    case 0xe2: resultBuilder.Append('т'); break;
                    case 0xe3: resultBuilder.Append('у'); break;
                    case 0xe4: resultBuilder.Append('ф'); break;
                    case 0xe5: resultBuilder.Append('х'); break;
                    case 0xe6: resultBuilder.Append('ц'); break;
                    case 0xe7: resultBuilder.Append('ч'); break;
                    case 0xe8: resultBuilder.Append('ш'); break;
                    case 0xe9: resultBuilder.Append('щ'); break;
                    case 0xea: resultBuilder.Append('ъ'); break;
                    case 0xeb: resultBuilder.Append('Ŧ'); break;
                    case 0xec: resultBuilder.Append('ь'); break;
                    case 0xed: resultBuilder.Append('э'); break;
                    case 0xee: resultBuilder.Append('ю'); break;
                    case 0xef: resultBuilder.Append('я'); break;
                    case 0xf0: resultBuilder.Append('№'); break;
                    case 0xf1: resultBuilder.Append('ё'); break;
                    case 0xf3: resultBuilder.Append('ѓ'); break;
                    case 0xf4: resultBuilder.Append('є'); break;
                    case 0xf5: resultBuilder.Append('ѕ'); break;
                    case 0xf6: resultBuilder.Append('і'); break;
                    case 0xf7: resultBuilder.Append('ї'); break;
                    case 0xf8: resultBuilder.Append('ј'); break;
                    case 0xf9: resultBuilder.Append('љ'); break;
                    case 0xfa: resultBuilder.Append('њ'); break;
                    case 0xfc: resultBuilder.Append('ќ'); break;
                    case 0xfd: resultBuilder.Append('§'); break;
                    case 0xfe: resultBuilder.Append('ў'); break;
                    case 0xff: resultBuilder.Append('џ'); break;
                    default:
                        throw new NotImplementedException(String.Format("0x{0:X2}", preprocessed[i]));
                }
            }

            return resultBuilder.ToString().ToCharArray();
        }
    }
}
