I need help with the encryption of a 140 character message

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

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.
Sorry not sure why it did not work, it is up now. As for the encryption its just something I need to create, so I don't think that violates anything.
And thanks for pointing out the missing attachment.

Sign in to comment.

Answers (2)

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.

1 Comment

Ok thanks, I will give that a shot! We have not covered the char command yet. Honestly by looking up and down these forums there seems be a lot still to learn really.
also on a side note I had forgotten the criteria attachment and that is now up if you wanted to take a look at that.
And thank you very much for the imput!

Sign in to comment.

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

I'll try using this as well, but we have not learned about those commands yet, so I hope I can use yours and James's advice. I had forgotten to attach the criteria earlier and now have that up it you wanted to take a look.
the coding I have right now is weak and riddled with errors and at best loosely fits the criteria. I worked in a sewing machine repair shop and apprenticed to a luthier before transferring from my community college. Basically what I'm trying to get at is that I've never had a talent with computers but I'm actively trying to change that. It is just aggravating to do so when it can mess with your GPA.
I'll attach what I have managed to mess with so far. Kind of blundering around a bit as I review and research.
Oh and thank you very much for the help.
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.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 3 Aug 2015

Commented:

on 5 Aug 2015

Community Treasure Hunt

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

Start Hunting!