Advertisement
Zeinab_Hamdy

Algorithm

Apr 11th, 2023
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.29 KB | None | 0 0
  1.  
  2.         ################  encoding #################
  3.        
  4. msg='Enter the message to encode it :';
  5. plainText=input( msg , 's')
  6.  
  7.  
  8. for i =1 : length(plainText)    
  9.       if ( plainText(i)>="a" && plainText(i)<="z")
  10.           continue ;          
  11.       elseif (plainText(i) !=" " )        
  12.           disp('can not be encode this message ')
  13.           return ;          
  14.       end
  15.   end
  16.  
  17. k= input('Enter the value of K :')
  18.    
  19. for i =1 : length(plainText)
  20.     if (plainText(i) !=" " )
  21.         plainText(i)= mod(plainText(i)-'a' + k  , 26) +'A';
  22.        
  23.     end    
  24. end
  25.  
  26.   disp('the encoded message : ');
  27.   disp( plainText);
  28.  
  29.  
  30.  
  31.  
  32.  
  33.         ################  decoding #################
  34.        
  35. msg='Enter the message to decode it :';
  36. plainText=input( msg , 's')
  37.  
  38.  
  39. for i =1 : length(plainText)    
  40.       if ( plainText(i)>="A" && plainText(i)<="Z")
  41.           continue ;          
  42.       elseif (plainText(i) !=" " )        
  43.           disp('can not be decode this message ')
  44.           return ;          
  45.       end
  46.   end
  47.  
  48. k= input('Enter the value of K :')
  49.    
  50. for i =1 : length(plainText)
  51.     if (plainText(i) !=" " )
  52.         plainText(i)= mod(plainText(i)-'A' - k  , 26) +'a';
  53.        
  54.     end    
  55. end
  56.  
  57.   disp('the decoded message : ');
  58.   disp(plainText);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement