Question: What have I done wrong? how can I change the massage to lower case? 1 function out-encrypt(cipher, message) %Checking for different cnditions Minimum Nargin check
What have I done wrong? how can I change the massage to lower case?


1 function out-encrypt(cipher, message) %Checking for different cnditions Minimum Nargin check 4 if nargin=2 5 error('Not Enough Input Arguments) 6 end %Cipher length check and uniqueness if length(cipher)~=26 || length(unique( cipher))~=26 error('Length of the cipher is not 26 or there are repeating elements') end 7 8 9 10 11 12 13 %Defining a Alphabet vector for cmparison alphabet='abcdefghijklmnopqrstuvwxyz'; cipher_check=cipher; 14 15 16 17 %Checking cipher whether it contains all elements from the alphabet if sum( lower(sort(cipher_check) ) ==alphabet) -=26 error('Cipher doesnt contain all unique elements from the alphabet') end 18 19 20 21 22 %Checking whether the message is a character vector if wischar(message) error('Message must be a character vector') 23 24 end 25 26 27 28 29 30 31 32 33 34 % Converting all the elements into lower case lower_message=lower(message); %Using a for loop to run through each element of the message for i=1: Length (lower_message) %Checking whether the element is a letter if isletter(lower_message(i)) %Finding the index from the alphabet vector idx=(alphabet==lower_message(i)); Repacing it with the cipher value out(i)=cipher(idx); else Keeping the original element if its not a letter out(i)=lower_message(i); end end 35 36 37 38 39 40 41 Output secret Message = 'ZVRYVF HD RNK FKDR!' Assessment: 2 of 3 Tests Passed (72%) Submit Correct Encryption 43% (43%) Encryption is case insensitive 29% (29%) 0% (28%) > Output matches case for cipher Cipher doesnt contain all unique elements from the alphabet Output message case should be the same as the cipher case. Total: 72% 1 function out-encrypt(cipher, message) %Checking for different cnditions Minimum Nargin check 4 if nargin=2 5 error('Not Enough Input Arguments) 6 end %Cipher length check and uniqueness if length(cipher)~=26 || length(unique( cipher))~=26 error('Length of the cipher is not 26 or there are repeating elements') end 7 8 9 10 11 12 13 %Defining a Alphabet vector for cmparison alphabet='abcdefghijklmnopqrstuvwxyz'; cipher_check=cipher; 14 15 16 17 %Checking cipher whether it contains all elements from the alphabet if sum( lower(sort(cipher_check) ) ==alphabet) -=26 error('Cipher doesnt contain all unique elements from the alphabet') end 18 19 20 21 22 %Checking whether the message is a character vector if wischar(message) error('Message must be a character vector') 23 24 end 25 26 27 28 29 30 31 32 33 34 % Converting all the elements into lower case lower_message=lower(message); %Using a for loop to run through each element of the message for i=1: Length (lower_message) %Checking whether the element is a letter if isletter(lower_message(i)) %Finding the index from the alphabet vector idx=(alphabet==lower_message(i)); Repacing it with the cipher value out(i)=cipher(idx); else Keeping the original element if its not a letter out(i)=lower_message(i); end end 35 36 37 38 39 40 41 Output secret Message = 'ZVRYVF HD RNK FKDR!' Assessment: 2 of 3 Tests Passed (72%) Submit Correct Encryption 43% (43%) Encryption is case insensitive 29% (29%) 0% (28%) > Output matches case for cipher Cipher doesnt contain all unique elements from the alphabet Output message case should be the same as the cipher case. Total: 72%
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
