Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE SOLVE by USING MATLAB Part 2 Encrypt and decrypt a string of your choice

ID: 3282147 • Letter: P

Question

PLEASE SOLVE by USING MATLAB

Part 2 Encrypt and decrypt a string of your choice using your own cipher. You may use any common characters but be sure to include them in your base number Output your alphabet to the command window. Output your cipher to the command window. ·Output your encrypted string to the cominand window. Output your decrypted string to the command window. Cryptography with an unknown cipher Suppose we are given an encrypted message: SLKGMNXCXWNIMHHSNIVBKBERELIHGBQSX.J We are told that the Hill cipher associated to this encryption is a 2x2 matrix and the first four letters are GEDC. Construct the cipher from this information and decrypt the message HINT: Use the fact that G E corresponds to S L and D C corresponds to K G

Explanation / Answer

I am providing a simple ROT13 encoder / decoder (i.e. alphabetical shift cypher with a shift value of 13 so that the encoder and decoder is exactly the same).

Please find the code below.

CODE

====================

function s_out = rot13(s_in, shift);

% ROT13 - ROT13 encryption / decryption
% This encrypts or decrypts a string using the ROT13 algorithm.
%
% Syntax: out = rot13(in,shift);
%
% Where in and out are strings, and shift is an optional
% alphabetical shift argument (default is 13, of course).

if nargin<2
shift = 13;
end;

a_up = 65:90;
a_lo = 97:122;

nums = double(s_in);
nums(ismember(nums,a_up)) = a_up(1)+mod((nums(ismember(nums,a_up))-a_up(1)+shift),26);
nums(ismember(nums,a_lo)) = a_lo(1)+mod((nums(ismember(nums,a_lo))-a_lo(1)+shift),26);
s_out = char(nums);

****NOTE: Please call rot13() function to encrypt/decrypt a message. Here, s_in is the input and s_out is the output.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote