0

is there a way to convert numbers to str in matlab

for example, 30120 turns into cat

where c is 03 a is 01 t is 20

here is my progress on RSA encryption/decryption I am trying to decrypt into plain text.

% 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)

1 Answer 1

1

From 30120 to 'cat':

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

Results in str = 'cat'. I think that's what you want.

Sign up to request clarification or add additional context in comments.

2 Comments

crud, so close except sprintf command cannot handle vpi numbers is there a way around this? is there a way for me to convert vpi number to a number that is compatible with sprintf command
the documentation for vpi states that you can convert it to struct and then access an array with the digit representation: s = struct(vpi_number); s.digits;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.