%% text from unicode pictogram (arbitrary-base encoding)
clc; clear all;
format compact
instring='▄▆▂▆ ▄█▄▄ ▄▆█▂ ▄▆█▂ ▄█▂█ ▄▆▆▂ ▄▆▆▄ ▄█▄▂';
charmap='▂▄▆█'; % length(charmap)=b
space=' '; % thin space
b=length(charmap);
for n=0:1:b-1;
instring(findstr(instring,charmap(n+1)))=num2str(n);
end
instring(findstr(instring,space))=' ';
instring=str2num(instring); % simplifies indexing
outstring='';
for n=1:1:length(instring);
outstring=[outstring char(base2dec(num2str(instring(n)),b))];
end
outstring
It works well enough. I suppose I could make it automagically find a minimal character set from the input pictogram string, but it wouldn't have any way of guessing the likely order. Granted, even a human would have to guess if the charmap used in encoding weren't conspicuously ordered.
No comments:
Post a Comment