Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matlab coding for caesar cipher algorithm
#1

matlab coding for caesar cipher algorithm

Introduction Caeser Cipher

So this is Matlab code for Caesar Cipher Encryption and Decryption.There are many security techniques like Cryptography .The technique which was used in the past days is very simple and easily breakable in its method first a secret key is choosed after choosing key it added to every bit of data for example our data is Data = Attend meeting at noon and Encryption key = 3 so key is of single bit its mean its easily breable in 2.5ms So Now A = C , T = W , E=H , N=Q , D=G , M=P , I=L , O=R , G=j .Now apply this on data and then Ecrypted Data will be Cwwhqg phhwlqj cw qrrq . Now lets move towards how to develop Matlab code.

Algorithm

First Take Input Form user and then calculate Length of string then declare two dummy arrays named array and input.Now whats in the variable x ???? String ??? No actually x variable contains Ascii values of the string like ascii of A is 65 and in the same way acsii of B is 66 and the ascii of last alphabet Z is 90. In the first loop to access single alphabet from the variable x and the result is saved i n input.
Now Select your Cipher Key which is also entered by user after then add the key value one by one in input1 variable and then save the result in array variable.
Now we have to handle both capital and small alphabets check if sum of ascii value and key is > than 122 (ascii of small z ) then its mean we have to shift our ascii values to start again from small z .To do this subtract array(i) for current alphabet from ascii of z (ascii =122) now add 96 to start from a (ascii = 97) but we will add 96 becuase there will be an extra shift so upto now small alphabets are handles in the same way Capital letters are handled and in the decryption reverse process is done but if one has problem in understanding the handling of capital letters and in decryption then comment and ask about your problem.


Matlab Implementation

function ceaser

clc
x=input( Enter Input Text = , s );

len=length(x);

array=[];
input1=[];
key = input( Enter Key Value );

for i=1:len
input1(i)=x(i);
end

for i=1:len
array(i)=input1(i)+key;

%handling small alphabets
if array(i)>122 && input1(i)>=97
array(i)=array(i)-122;
array(i)=array(i)+96;
end

%handling capital alphabets
if array(i)>90 && input1(i)<=90
array(i)=array(i)-90;
array(i)=array(i)+64;
end

end

disp( Ecryption Result );
ENCRYPT = char(array)

for i=1:len
array(i)=array(i)-key;

%handling small alphabets in Decryption

if array(i)<=97 && input1(i)>=97
array(i)=97-array(i);
array(i)=123-array(i);
end

%handling capital alphabets

if array(i)<65 && input1(i)<=90
array(i)=65-array(i);
array(i)=91-array(i);
end
end

disp( Decryption Result );

DECRYPT = char(array)

Source Code

Like , share this post on Facebook , Twitter by using left moving Social Sharing block and follow us on Facebook Page , Twitter and do comment and enter your email. After you have done you will automatically get source code in your mail. Note : This will be auto generated mail you can t get until you follow above method.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.