-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubstitution_Cipher_user_input.m
More file actions
35 lines (21 loc) · 1.05 KB
/
Substitution_Cipher_user_input.m
File metadata and controls
35 lines (21 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function plaintext=Substitution_Cipher_user_input(x)
letter_frequency_order=Freq_order(x); % get all letters ordered from most to leased based on frequency (a=0,...,z=25)
plaintext_order='etaoinsrhldcumfpgwybvkxjqz'; % the corresponding order of english plantext
y=x; %Initiate y
% the for loop substitude each letter in x with the corresponding one in plaintext_order
for i=1:26
y(x==num_to_lett2(letter_frequency_order(i)))=plaintext_order(i);
end
%The answer is not true but we can see that the plaintext is the united
%states constitution
% take user input
y_suggested=y;
disp('Do you have any suggestion to switch between letter?')
user_suggestion = 'write it as one multiple rows matrix each row has the form [old letter new letter], put in numbers, a=0, ..., z=25 ';
s= input(user_suggestion);
%the user inputs suggestion, it should be s=[21 22;20 5;12 20;18 8;8 18;5 12;6 1;23 9;22 24;1 21;24 6;10 23;9 10]
for i=1:size(s,1)
y_suggested(y==num_to_lett(s(i,1)))=num_to_lett(s(i,2)); %apply suggestion
end
plaintext=y_suggested;
end