Advertisement
Zeinab_Hamdy

Encoding ceaser using matlab

Apr 12th, 2023 (edited)
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.73 KB | None | 0 0
  1. function Encoding_ceaser()
  2.     msg='Enter the message to encode it :';
  3.     plainText=input( msg , 's');
  4.          for i =1 : length(plainText)    
  5.              if ( plainText(i)>="a" && plainText(i)<="z")
  6.                   continue ;          
  7.              elseif (plainText(i) ~=" " )        
  8.                   disp('can not be encode this message ')
  9.                   return ;          
  10.              end
  11.          end
  12.  
  13.     k = input('Enter the value of K :');
  14.     k = mod(k , 26 );
  15.    
  16.         for i =1 : length(plainText)
  17.             if (plainText(i) ~=" " )
  18.               plainText(i)= mod(plainText(i)-'a' + k  , 26) +'A';
  19.             end    
  20.         end
  21.  
  22.   disp('the encoded message : ');
  23.   disp( plainText);
  24.  
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement