MATLAB Answers

variable size matrix and converting letters to numbers

3 views (last 30 days)
Fatma Alnabrisi
Fatma Alnabrisi on 22 Nov 2019
Commented: Jan on 27 Nov 2019
Hello everyone,
I'm working on a college project that encrypt text messages using LU decomposition and matrix inverse methods.
I need your help in how to let the user enter a variable size matrix to store the key and another for the plain text.
Moreover, how could I convert the letters into certain numbers.
Another last question, how to fill the array with null operators in case the plain text is too short to fill it.
Thanks

  2 Comments

Fatma Alnabrisi
Fatma Alnabrisi on 25 Nov 2019
My input at the sender side:
the user is asked to enter the key which has to be a sequare matrix K (nxn) .
--> I need to get the dimension of the key matrix.
the user then enters the plain text.
I need to convert the letters into numbers and store them in matrix P (nxm).
( A --> 1 , B --> 2 , ....., Z --> 26 , ... )
if the length of the plaint text is less than n*m, i need to fill the matrix with zeros.
Then some manipulations on the K matrix and P matrix have to be done to get the ciphertext matrix and convert the numbrs back into letters.
Jan
Jan on 27 Nov 2019
@Fatma: Please consider, that the readers do not know, what you exactly want. While "My input an the sender" is most likely clear to you, there is no chance to guess, what this eactly means. Perhaps "sender" means a TCP/IP connection, or the inputs of a function, or a remote or local GUI, a web service, etc. "Asked to enter the key" can mean a variety of things also.
Converting the characters to number is easy:
num = txt - 'A' + 1;
Filling a matrix with zeros is easy also:
M = zeros(n, n);
Now inserting the existing values in column order:
M(1:m) = num;
I do not understand, what m is.
The description is still far too vague to offer an explicite suggestion.

Sign in to comment.

Accepted Answer

Jan
Jan on 22 Nov 2019
"user enter a variable size matrix": It depends on how you want to implement this: by a GUI, as Matlab code, as text file, in Excel?
"another for the plain text": Of course a text file would be my first idea. But a GUI with an edit field would be sufficient also.
"how could I convert the letters into certain numbers": Simply by using the double() command, which converts the characters to their ASCII codes.
"fill the array with null operators": What is a "null operator"? I guess simply using zeros might be fair.

  3 Comments

Fatma Alnabrisi
Fatma Alnabrisi on 22 Nov 2019
Thank you for your answer.
Actually it doesn't matter which way to implement reading plain text wether from a text file or by GUI. I think using text file is easier.
What you've mentioned sounds good and similar to how I thought about it. But I need help in how to code these instructions in Matlab.
Jan
Jan on 23 Nov 2019
@Fatma: Before the readers can help you efficiently, you have to explain the problem with more details. Currently we know only a rough explanation and it is unclear, which kind of help you need. It matters if the input should be just one or 2 sentences, or 500 pages of text.
Can you post a small and meaningful example of the wanted inputs and outputs?
Fatma Alnabrisi
Fatma Alnabrisi on 25 Nov 2019
I've added some extra details. can you please look at them and help me out.

Sign in to comment.

More Answers (0)


Translated by