Caesar Cipher. Read in from text file question.

So I have do decrypt a Caesar Cipher from a text file. It looks like this

<2D or <24A or <-2F (go down -2, so up 2) or <4TA<2

And I am so lost. I have been looking up stuff and attempting to use peek and atoi which I have never heard of until today.

When ever a < is read. The following numbers and signs determine the shift value. And in the last example, if the start of the text file has another '<' or '>' in it, they it adds or subtracts them to the shift value.


So far my code looks like this. You might want to cover your eyes.

http://pastebin.com/tcnxFZiY

My approach is to just read 1 character. Then have a bunch of if's and the loop through the whole text file till I hit the end trigger '#'. I am really having trouble with my shiftMod function. I just added some atoi thing that I had to read about by myself.

Can anyone help me with that function. The goal is to first figure out if it is a '<' or a '>' as done with the first ifs. Then I have to read the next character(s) that are numbers, and STOP at the first alpha. Ex: >24D. It reads the >, but i can't figure out how to read the 2 then the 4, to make the shift value UP 24 letters. So D would wrap around to F.

Should I read them as characters or ints? Ints would be easier, but I have no idea how to pull them out of the .txt file.

Any help would be amazing. Thank you!
Read them as int and then increase the char by the int.
For <24A

1
2
3
4
5
//Read 24 in d (DIY)
//Read A in c
c+=d



Let me know if that helps
Topic archived. No new replies allowed.