0% found this document useful (0 votes)
42 views

Program: Cipher Text

The document is a MATLAB program that encrypts and decrypts plaintext using a Caesar cipher. The program takes in plaintext and a key as input, shifts each character by the key, and outputs the encrypted ciphertext. It then decrypts the ciphertext by shifting the characters in the opposite direction of the key back to the original plaintext. The program runs through this process for 3 examples, correctly encrypting and decrypting the inputs.

Uploaded by

Piyush Jain
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Program: Cipher Text

The document is a MATLAB program that encrypts and decrypts plaintext using a Caesar cipher. The program takes in plaintext and a key as input, shifts each character by the key, and outputs the encrypted ciphertext. It then decrypts the ciphertext by shifting the characters in the opposite direction of the key back to the original plaintext. The program runs through this process for 3 examples, correctly encrypting and decrypting the inputs.

Uploaded by

Piyush Jain
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program : Cipher Text

clc; clear all; close all; for x=1:3; p=input('Enter Plain Text: ','s'); p=double(p); k=input('Enter key:'); k=mod(k,26); c=(p+k); for i=1:length(c) if p(i)>=65&&p(i)<=90 if c(i)>90 c(i)=65+mod(c(i),90)-1; end else if p(i)>=97&&p(i)<=122 if c(i)>122 c(i)=97+mod(c(i),122)-1; end end end end disp('The encrypted o/p is:'); disp(char(c)) o=(c-k); for j=1:length(c) if c(j)>=65&&c(j)<=90 if o(j)<65 o(j)=90-mod(65,o(j))+1; end else if c(j)>=97&&c(j)<=122 if o(j)<97 o(j)=122-mod(97,o(j))+1; end end end end disp('The decrypted o/p is:') disp (char(o)) end

OUTPUT:
Enter Plain Text: thakur college of engineering Enter key:36 The encrypted o/p is: drkueb*myvvoqo*yp*oxqsxoobsxq The decrypted o/p is: thakur college of engineering Enter Plain Text: THAKUR COLLEGE OF ENGINEERING Enter key:63 The encrypted o/p is: ESLVFC+NZWWPRP+ZQ+PYRTYPPCTYR+ The decrypted o/p is: THAKUR COLLEGE OF ENGINEERING Enter Plain Text: THAKUR COLLEGE of Engineering Enter key:5 The encrypted o/p is: YMFPZW%HTQQJLJ%tk%Jslnsjjwnsl The decrypted o/p is: THAKUR COLLEGE of Engineering

You might also like