%-------------------------------------% % Homework 7: p.4 % % Date: 11/11/2002 % % % % Gun Srijuntongsiri % % gs61 % % ?????? % %-------------------------------------% % Variables: % str = user inputted string % shift = number of shifts % Ask for the string and shift str = input('Enter a string to be encrypted: ','s'); shift = input('How many to shift? '); str = lower(str); % Change to lowercase disp(['Original string (converted to lowercase): ',str]); % Shift one character at a time, from the first to the last for i=1:length(str) % Shift to the left by $shift$ amount str(i)=char(str(i)-shift); % Now taking care of rollover from 'a' back to 'z' if str(i) < 'a' str(i) = char(str(i)+'z'-'a'+1); end end % Output the shifted result disp(['Encrypted string : ',str]);