0

有没有办法在matlab中将数字转换为str

例如 30120 变成 cat

其中 c 是 03 a 是 01 t 是 20

这是我在尝试解密为纯文本的 RSA 加密/解密方面的进展。

% variables

p=vpi('22953686867719691230002707821868552601124472329079')
q=vpi('30762542250301270692051460539586166927291732754961')
e=vpi('555799999999999');
n=(p.*q)
phi=((q-1).*(p-1))

% how to convert plaintext to integer mod 26


abc = 'abcdefghijklmnopqrstuvwxyz';
word = 'acryptographicallystrongrandomnumbergeneratorwhichhasbeenproperlyseededwithadequateentropymustbeusedtogeneratetheprimespandqananalysiscomparingmillionsofpublickeysgatheredfromtheinternetwasrecentlycarriedoutbylenstrahughesaugierboskleinjungandwachteracryptographicallystrongrandomnumbergeneratorwhichhasbeenproperlyseededwithadequateentropymustbeused';  

[temp1, temp2, temp3, temp4, temp5, temp6, temp7,temp8,temp9] = split(word)

[int1,int2,int3,int4,int5,int6,int7,int8,int9] = intsplit(temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9)

[encrypt1, encrypt2, encrypt3, encrypt4, encrypt5, encrypt6, encrypt7, encrypt8, encrypt9] = encrypt_this(int1, int2, int3, int4, int5, int6, int7, int8, int9)

[decrypt1, decryt2, decrypt3, decrypt4, decryt5, decrypt6,decrypt7, decryt8, decrypt9] = decrypt_this(encrypt1, encrypt2, encrypt3, encrypt4, encrypt5, encrypt6, encrypt7, encrypt8, encrypt9)
4

1 回答 1

1

从 30120 到“猫”:

num = 30120;
l = ceil(numel(num2str(num))/2); % number of characters
num2 = sprintf('%06i', num);   % num in string form, with leading zero if needed
                               % '030120'
str = '';
for i = 1:l
    str = [str char(96+str2num(num2(2*i-1:2*i)))]; 
end % 96 is the ASCII offset needed to get a=1, c=3 etc like in your example

结果在str = 'cat'. 我想这就是你想要的。

于 2012-10-07T00:11:52.493 回答