how do you use a loop to convert letters to numbers?

1 view (last 30 days)
I need to make an encryption involving the use of a loop that converts letters to numbers, and also the numbers back into letters. I had made an earlier post but after overviewing my requirements found that the other methods provided would not be applicable.
• You must use at least one loop that converts letters to numeric values. No other method, shortcut, or built in matlab command will be accepted.
So I need to be able to do that. We had just covered this in class friday and my understanding of the matter is shaky, I'm new into the world of coding. Any help would be greatly appriciated. I will have an attached pdf with the other regulations involved. I am not asking for the work to be done for me but any tips help/advice is welcomed.

Answers (1)

Image Analyst
Image Analyst on 4 Aug 2015
Hint: Make a string variable s='abcdefghijklmnopqrstuvwxyz 1234567890'. Then use a for loop and functions like find(), strfind(), length(), and/or char().
  2 Comments
James DiNinno
James DiNinno on 4 Aug 2015
Could you please post an example of what to do with the loop? It has me stumped and I am getting nowhere with it. I can get numbers into letters just not the other way around. Thanks, James.
Image Analyst
Image Analyst on 4 Aug 2015
James, here is a huge start on it:
plainText = 'hello world';
cypherKey = 'abcdefghijklmnopqrstuvwxyz 1234567890'
for k = 1 : length(plainText)
index = strfind(cypherKey, plainText(k));
fprintf('Converting %c into %d\n', plainText(k), index);
encryptedText(k) = .....
end
It's virtually done. If you want to make it more robust you'll have to handle upper and lower case as well as other symbols, and handle characters that are not in the key.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!