I need help with the encryption of a 140 character message
2 views (last 30 days)
Show older comments
I need to have a code that can take a message up to 140 characters and turn it into numbers. a=1 b=2 ect... ect... Then it will need to be able to take the numeric message and convert it back to letters. I'll attach the criteria that the code needs to meet.
This is for an online class that I am taking. I am not looking for someone to do the work for me but looking for help. My professor is conveniently gone away at a conference or something and will not be able to answer any questions. A little last minute on my part yes, but we just learned about looping Friday and this is due this coming Wednesday. Any help would be much appreciated!
2 Comments
Walter Roberson
on 3 Aug 2015
You forgot to attach the criteria.
Caution: if the encryption is not trivial, it might be illegal to host the discussion on Mathwork's servers, for legal reasons. Considering a certain Adobe lawsuit, I am not certain that it is legally safe to even talk about ROT13.
Answers (2)
James Tursa
on 3 Aug 2015
Edited: James Tursa
on 3 Aug 2015
E.g.,
s = 'a string'; % original string
d = double(s); % string turned into numbers
t = char(d); % numbers turned back into string
If you want more specific encoding, then alter the "d = ..." line into whatever encoding you want, with appropriate reverse changes to the "t = ..." line as well.
Geoff Hayes
on 3 Aug 2015
James - what have you tried so far? Please describe what you have attempted and where you are getting stuck. If it on the conversion of letters to numbers, then you may want to consider converting the letter to an integer using uint8 (or to another numeric data type) and then converting the number to a string using char.
For example,
charToEncrypt = 'a';
encryptedChar = uint8(charToEncrypt);
decryptedChar = char(encryptedChar);
In the above,
encryptedChar =
97
and
decryptedChar =
a
3 Comments
Geoff Hayes
on 5 Aug 2015
James - look closer at the input function. You will want to use the 's' option so that the string (to encrypt) is not evaluated as an expression by MATLAB.
I suspect that you will then want to iterate over each element of the string and compare it against your map (the 'a' to 0, 'b' to 1, etc.) using a for loop. Consider using Map Container to manage the mapping. Your keys would be the letters and numbers to encrypt, and the values would be the encrypted equivalent of that key.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!