MATLAB project to decrypt messages

In summary, the conversation is about a MATLAB project that decrypts messages using only uppercase characters and spaces. The program works but does not print spaces, instead printing a 7. The solution is to use an outermost IF statement to avoid converting spaces into 7.
  • #1
G'mo
3
0
Hi everyone. I have a MATLAB project to decrypt messages using only uppercase characters and spaces(i.e no punctuation). The problem is that my program is working but does not print spaces, instead of a space it prints 7. If anyone can help, I'll be very greatful.Here is my program:

a1 = input('Please enter a sentence: ','s');
p = upper(a1); % Change the text to uppercase
double(p); % String to ASCII codes

for i = 1:numel(p) % Iterate as long as there are characters
% in the string
if (p(i) ~= 32) & (p(i) > 67)
p(i) = p(i) - 3;
elseif (p(i) <= 67)
p(i) = p(i) + 23;
else
* (p(i) == 32)
end
end
disp(p)

* This part seems to be useless.
If the user inputs: khoor pb iulhqg
output: HELLO7MY7FRIEND
 
Physics news on Phys.org
  • #2
Just replace any occurence of '7' in p with ' ' before disp(p):

for i=1:numel(p)
if(p(i)=='7')
p(i)=' ';
end
 
  • #3
Your problem appears to be this part:

Code:
elseif (p(i) <= 67)
  p(i) = p(i) + 23;

...it converts 32 (' ') into 32 + 23 = 55 ('7').

If you don't want to convert spaces into anything then use an outermost IF, something like this:

Code:
if (p(i) ~= 32)
  if (p(i) > 67)
    p(i) = p(i) - 3;
  else
    p(i) = p(i) + 23;
  end
end

(I'm unsure of the syntax but you should get the idea.)
 

1. What is MATLAB and how is it used for decrypting messages?

MATLAB is a powerful software platform that is commonly used for numerical computing and data analysis. It can also be used for cryptography, including decrypting messages. MATLAB has built-in functions for encryption and decryption, making it a convenient tool for this task.

2. Can MATLAB decrypt any type of message?

MATLAB can decrypt messages that have been encrypted using common techniques such as Caesar cipher or Vigenere cipher. However, it may not be able to decrypt messages that have been encrypted using complex algorithms or advanced techniques.

3. How do I input a message into MATLAB for decryption?

You can input a message into MATLAB by using the 'input' function and specifying the message as a string. Alternatively, you can also import a text file containing the encrypted message into MATLAB and use it for decryption.

4. Are there any prerequisites for using MATLAB for decrypting messages?

Yes, you will need to have a basic understanding of MATLAB and its syntax in order to use it for decrypting messages. You may also need to have a basic understanding of cryptography and different encryption techniques to effectively decrypt messages using MATLAB.

5. Can I automate the decryption process using MATLAB?

Yes, MATLAB allows you to write scripts and functions to automate the decryption process. You can also use loops and conditional statements to decrypt multiple messages at once. This can be especially useful for decrypting large volumes of messages.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
275
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
10K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
Back
Top