Im trying to decrypt a message in matlab. My code can decrypt some shorter messages with a low key, but when I try to decrypt a long message with like a key of 9 it wont work. I thought my code was correct, but I guess I have some flaw in it. Can anyone help? (Using ASCII values)
original_message=input('Please enter the message you want decrypted:', 's') % original message
key=input('What will be the encryption key you are using:')number_message=double(original_message)for k=1:length(original_message) if number_message(k)>=65 && number_message(k)<=90 number_message(k)=number_message(k)-key if number_message(k)<=90 number_message(k)=number_message(k)+26 end elseif number_message(k)>=97 && number_message(k)<=122 number_message(k)=number_message(k)-key if number_message(k)<=122 number_message(k)=number_message(k)+26 end endendfprintf('The decrypted message is %s \n',number_message)
Best Answer