Need help with Matlab Design a cipher that takes in plaintex
Need help with Matlab
Design a cipher that takes in \"plaintext\" (your message)and some \"key\" number and Outputs \"ciphertext\"(according to the key that is given in an argument of the function).You may find the following skeleton code to be useful: function ciphertext =caesar_cipher_encryption(plaintext, key) %{Caesar_Cipher Performs the very simple Caesar Cipher on a given string \"plaintext\" with the given \"key\" plaintext = STRING of the original message. key = an integer number of shifts that the cipher will perform on each letter. ciphertext= a STRING Output after the cipher has completed. %} ciphertext - double(plaintext); %This allows us to perform numerical manipulations on the ASCII %representations of plaintext. %%%%%%% Perform the cipher HERE %%%%%%%%%%%%% ciphertext = char(ciphertext); %This converts the ciphertext back into a string. end (b) Pass the message \"It\'s a secret to everybody\" into your cipher, with a key that you decide. Now, encode this cipher text with your FSK encoder. Show the code you used to accomplish this.Solution
a)
code :
function ciphertext=caesar_cipher_encryption(plaintext,key)
if key>26
error(\'Key must be in rang from 1 to 26\')
end
ciphertext=double(plaintext)+key;
l=find(ciphertext>122);
ciphertext(l)=ciphertext(l)-26;
l=find(ciphertext>90);
l=find(ciphertext(l)<97);
ciphertext(l)=ciphertext(l)-26;
l=find(plaintext==32);
ciphertext(l)=32;
ciphertext=char(ciphertext);
disp(\' \')
disp(\'Plain Text P=\')
disp(plaintext)
disp(\' \')
disp(\'Cipher Text \')
end
example
caesar_cipher_encryption(\'helloworld!\',3)
Plain Text P=
helloworld!
Cipher Text
ans =
khoorzruog$
b)
function ciphertext=caesar_cipher_encryption(plaintext,key)
if key>26
error(\'Key must be in rang from 1 to 26\')
end
ciphertext=double(plaintext)+key;
l=find(ciphertext>122);
ciphertext(l)=ciphertext(l)-26;
l=find(ciphertext>90);
l=find(ciphertext(l)<97);
ciphertext(l)=ciphertext(l)-26;
l=find(plaintext==32);
ciphertext(l)=32;
M=128; % modulation index
freqsep=2;%frequency seperation
n=2;% number of samples
fs=256;%sampling frequency
fsk_ecoded_data=fskmod(ciphertext,M,freqsep,n,fs); % fsk ecoding
ciphertext=char(abs(fsk_ecoded_data));
end

