Crypt a message with matlab [closed] - matlab

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have one question.
I didn't work with MatLab before.
how I read a message from a file. text? and how I crypt and decrypt it?
I need this work for my study project.

To read text:
fid=fopen(filename,'r');
text=fread(fid,'*char')';
fclose(fid);
To encrypt you can use whatever encrpytion suite you want. look here for aes implementation.
Very simple enc/dec algorithem is xoring the text with some key:
filename=('my_cypher.m');
key='Justin Bieber'; %some very secret key
fprintf('\n------------Text-------------\n');
fid=fopen(filename,'r');
text=fread(fid,'*char')';
fclose(fid);
text(text==13)=[]; %remove windows CR for readablity
disp(text);
key=uint8(key);
text=uint8(text);
lenkey=length(key);
text(end+1:end+lenkey-mod(length(text),lenkey))=32; %add extra spaces for reshape.
fprintf('\n------------Cipher-------------\n');
cipher = reshape(bitxor(reshape(text,[],lenkey),key),1,[]);
disp(char(cipher));
fprintf('\n------------Decrpyt-------------\n');
decrpyt = reshape(bitxor(reshape(cipher,[],lenkey),key),1,[]);
disp(char(decrpyt));

Related

Is it possible to plot bars with filled pattern in Matlab [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Is it possible to plot bars with filled pattern in Matlab, like this figure?
I attempted to use applyhatch_pluscolor link however, I couldn't make it work (attempt below). Is there an easy / feasible alternative?
Test code:
bar(rand(3,4));
[im_hatch,colorlist] = applyhatch_pluscolor(gcf,'\-x.',1,[],[],150);
Then I changed the source code, from bits = hardcopy(h,'-dzbuffer',['-r' num2str(dpi)]); to bits = print(h,'-RGBImage',['-r' num2str(dpi)]);.
I got the figure below. However, this is still far away form the desired result.

Matlab script to rename signal name [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have simulink block which has thousands of input signal for example which contains a text TRXA
AIM1_Freshness_TRXA_FCC,
AIM2_Freshness_TRXA_FCC
I need to create exact replica of the model only change is TRXA is changed to TRXB
AIM1_Freshness_TRXB_FCC ,
AIM2_Freshness_TRXB_FCC
Any easy or matlab script to do that
Does the following help?
open_system('your_model')
x = find_system('RegExp','on','FindAll','on','Name','TRXA');
for idx=1:size(x,1)
name_orig = get_param(x(idx),'Name');
set_param(x(idx),'Name',strrep(name_orig,'TRXA','TRXB'));
end

How to create a a:d:b vector to create and display "sin(0), sin(pi/n), sin((2*pi)/n), . . . , sin(2*pi)]" [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have been trying for a while to get this to work but I don't seem to be getting any closer to a solution.
I'm not sure of what the pattern is and what to write for the "d" value in a:d:b
Clearly you want to start from 0 (a) and go to 2*pi (b).
Now the question comes what is your step size (d)?
From your example you can see that you are changing from 0 to pi/n.
And from pi/n to 2*pi/n.
This means your step size is d=pi/n
Once you defined your n, e.g:
n=10;
you can do the rest like this:
x=0:(pi/n):(2*pi)
y=sin(x);

Image processing in Matlab [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I took this from the Matlab help section:
text(size(I,2),size(I,1)+15, ...
'Image courtesy of Massachusetts Institute of Technology', ...
'FontSize',7,'HorizontalAlignment','right');
I don't understand how it works, could anyone explain it to me?
https://www.mathworks.com/help/matlab/ref/text.html
In summary:
x = size(I,2)
y = size(I,1)+15
"..." is just the statmentment line continuation character in matlab (it is basically saying, do not end this statement here, but rather continue reading next line)
actual text = 'Image courtesy of Massachusetts Institute of Technology'
The next 4 arguments are name-value pairs (as described in the link above). Basically, it allows you to grab a particular setting and apply it a value based on its name.
font size is set to 7 and horizontal alignment is set to right.

Searching through a large text file in Matlab [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Assuming we use Matlab, what is the best way to search for a string in a large text file (can be bigger than 1GB)? Reading the entire file into memory would be costly.
You need to look into this:Importing Large text data.
The method would be to use blocks. Load Data in blocks.
It can be done by the range input argument in xlsread. In the range itself, you can specify the columns as well..
Syntax:
num = xlsread(filename,sheet,xlRange)
Example:
filename = 'myExample.xlsx';
sheet = 1;
xlRange = 'B2:C3';
subsetA = xlsread(filename, sheet, xlRange)