how do you use a loop to convert letters to numbers?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposte (1)
Image Analyst
il 4 Ago 2015
Hint: Make a string variable s='abcdefghijklmnopqrstuvwxyz 1234567890'. Then use a for loop and functions like find(), strfind(), length(), and/or char().
2 Commenti
Image Analyst
il 4 Ago 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.
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!