1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | %% 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