Simple Message Encryption with Matricies

2 次查看(过去 30 天)
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!

采纳的回答

Walter Roberson
Walter Roberson 2019-11-18
>> 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 个评论
lynn777
lynn777 2019-11-18
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.

请先登录,再进行评论。

更多回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-11-18
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'

类别

Help CenterFile Exchange 中查找有关 Syntax for States and Transitions 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by