i have a question in using c++. i have an assignment due where i need to decode a message by changing letters by a set amount. for example a with a shift of 3 would be d. it will be denoted in the file given by a character like %2 which would be a shift of 2. i am looking for how to write a program to accomplish this. it uses something like pass by reference but i am not too familiar with this. i would love any help to get the project started. - fyi the stuff we need to decode is given in a .txt file and the program will read the file. it also needs to hvae error codes for things that don't work. thank you
Question on encyrption in c++?
You're talking about a Caeser cipher, or ROT3 here. It'd help to understand the problem, and how the cipher works, then worry about the code (pass by reference, etc) later.
Regarding the cipher, read the wikipedia. Realize also that it can be defeated pretty trivially with some letter counting and knowing a little of the statistics of English (or your language of choice).
Regarding the code, it's not clear what you're passing by reference, so I'll leave that to you. To get the value given some letter, you can do it in any number of ways... determine the offset to A (the value of which would be the ascii value), subtract off A to get an alphabet with A as 0 and Z as 25, add your rot, mod by 26 and add A back to get the output letter. Or even better, you could figure out your rot at the beginning, do it once for each letter that you store in a lookup table and just do it as a monoalphabetic replacement. Go nuts, figure out how it'd be fun to do.
Just wait till you get into columnar transpositions :D
Reply:maybe somehow convert "3" into ASCI text, then subtract that ASCI value to the Value that will turn into a "%". to convert ASCI text back, you will need this statement:
static_cast%26lt;char%26gt;
i think thats right, havnt taken it in a while.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment