Created
October 16, 2015 06:29
-
-
Save longdog/aaaa894b1052ee1788d7 to your computer and use it in GitHub Desktop.
МДК2 - 5-битная кодировка телеграфных аппаратов. Страшный секрет русского варианта этой кодировки мне удалось найти в древнем манускрипте “Стартстропный телеграфный аппарат СТА-М67″.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Longdog.Encoding | |
{ | |
/// | |
/// MDK2 decoding | |
/// | |
public class Mdk2 | |
{ | |
private static char[,] codepage = new char[3,32]{ | |
{(char)1,'E',(char)10,'A',' ','S','I','U',(char)13,'D','R','J','N','F','C','K','T','Z','L','W','H','Y','P','Q','O','B','G',(char)2,'M','X','V',(char)0}, | |
{(char)1,'Е',(char)10,'А',' ','С','И','У',(char)13,'Д','Р','Й','Н','Ф','Ц','К','Т','З','Л','В','Х','Ы','П','Я','О','Б','Г',(char)2,'М','Ь','Ж',(char)0}, | |
{(char)1,'3',(char)10,'-',' ','`','8','7',(char)13,'$','4','Ю',',','Э',':','(','5','+',')','2','Щ','6','0','1','9','?','Ш',(char)2,'.','/','=',(char)0} | |
}; | |
/// | |
/// Перекодировка из мдк2 в windows-1251 (decode mdk2 to windows-1251) | |
/// | |
/// строка в кодировке мдк2 | |
/// строка в кодировке windows-1251 | |
public static string Convert(string str) | |
{ | |
char[] toCh = str.ToCharArray(); | |
string str2=""; | |
byte foo=0; | |
try | |
{ | |
foreach (char c in toCh) | |
{ | |
char bar = codepage[foo,(byte)c]; | |
if ((byte)bar<3) | |
{ | |
foo = (byte)bar; | |
} | |
else | |
{ | |
str2 += bar; | |
} | |
} | |
} | |
catch (System.Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
return str2; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment