Simple Message Encryption with Matricies
2 views (last 30 days)
Show older comments
lynn777
on 18 Nov 2019
Commented: Walter Roberson
on 18 Nov 2019
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
Accepted Answer
Walter Roberson
on 18 Nov 2019
>> 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
More Answers (1)
KALYAN ACHARJYA
on 18 Nov 2019
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
See Also
Categories
Find more on Syntax for States and Transitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!