MATLAB Answers

0

Simple Message Encryption with Matricies

Asked by Lynn Vorwick on 18 Nov 2019 at 6:16
Latest activity Commented on by Walter Roberson
on 18 Nov 2019 at 21:12
Trying to demonstrate message encryption with multiplicaiton o fmatricies and inverse matricies.
Code is as follows:
clear; clc;
M = [72 97 112; 112 121 32; 84 104 97; 110 107 115; 103 105 118]
N = [1 5 8 ; 4 4 2 ; 7 7 7];
NI = inv(N);
E = M*N;
F = E * NI;
FE = char(F(1,:))
The first three letters (FE) keep coming out as "Hao" instead of "Hap". Anyone know what is going on here? I even converted these values from the character string to doubles first so I know the ASCII string is accurate to the message. Thanks for any help!

  0 Comments

Sign in to comment.

2 Answers

Answer by Walter Roberson
on 18 Nov 2019 at 8:54
 Accepted Answer

>> mod(F(1,:),1)
ans =
4.2632564145606e-14 0 0.999999999999943
char() truncates rather than rounding so 111.999999999999943 would display as 112 in the format you are using, but it is not quite 112 and char() would convert to position 111.

  3 Comments

How would I fix this in the code?
I ended up fixing it by simply using the commands "num2str" and "str2num" before using the "char" command to read the message :) thanks for the help.
Or you could fix it by using round()

Sign in to comment.


Answer by KALYAN ACHARJYA on 18 Nov 2019 at 8:14

Please di read here char
As per the char character array
>> ascii = char(reshape(32:127,32,3)')
ascii =
3×32 char array
' !"#$%&'()*+,-./0123456789:;<=>?'
'@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_'
'`abcdefghijklmnopqrstuvwxyz{|}~'
In the code
>> F(1,:)
ans =
72 97 112
Hence
>> FE=char(ans)
FE =
'Hao'
where
>> char(72)
ans =
'H'
>> char(97)
ans =
'a'
>> char(112)
ans =
'p'

  0 Comments

Sign in to comment.