Simple Message Encryption with Matricies

2 ビュー (過去 30 日間)
lynn777
lynn777 2019 年 11 月 18 日
コメント済み: Walter Roberson 2019 年 11 月 18 日
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.
Walter Roberson
Walter Roberson 2019 年 11 月 18 日
Or you could fix it by using round()

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeSyntax 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