4 Replies - 400 Views - Last Post: 09 October 2012 - 04:22 PM Rate Topic: -----

#1 acidfire00  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-October 12

Need help with decryption program

Posted 09 October 2012 - 11:22 AM

Hey guys, I'm new to c++ and I'm a little stumped on this assignment. I need to create a decryption program, basically the same assignment as this: http://www.dreaminco...ption-program/.

I'm not asking for anyone to write me the code, I understand how the decryption works. There program asks for a file name, then it will ask for three integers from 0-26 corresponding to the alphabet. These three integers are the key to the code. Each of the text files given to us are encrypted. If my three integers are 5 10 and 15, the first letter originally entered will be converted to 5 letters up on the alphabet. Then, the second letter with a 10 and the third letter, 15. I need to reverse this, and from what I've seen, the ideal way is to do it using the ASCII table yet somehow have it to not convert spaces, periods and any other form of punctuation and account for capital and lowercase letters while making sure that I loop/round back to beginning of the alphabet with the sequence of those three number for every three letters.

I don't know what functions would do this. Sorry for any vagueness, I didn't put any code up, simply because of the link I have to another person's example and mine would not be helpful in understanding the situation.

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with decryption program

#2 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1576
  • View blog
  • Posts: 3,004
  • Joined: 30-May 10

Re: Need help with decryption program

Posted 09 October 2012 - 11:33 AM

In #include <ctype>, you have things like islower(), isupper(), tolower(), toupper() and so on.

Next, you should read up on what the % operator does. It will be useful when you try and wrap 'z' round to 'a' for example.

I could post 1 line of code, but that would pretty much give the whole game away, so let's see what you can figure out first.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3169
  • View blog
  • Posts: 9,595
  • Joined: 05-May 12

Re: Need help with decryption program

Posted 09 October 2012 - 12:03 PM

Salem_c is quite correct about there being an elegant solution using the modulus operator. But if you aren't mathematically inclined (like me) and haven't seen the trick/pattern before, you can always resort to writing code that does boundary checks.

For example, this code computes angles around a circle. When it notices that values have gone past 360, it moves things back into scale:
int direction = 0;

while (getUserInput(&key))
{
    switch(key)
    {
    case Left:
        direction -= 15;
        break;
    case Right:
        direction += 15;
        break;
    }

    if (direction >= 360)
        direction -= 360;

    if (direction < 0)
        direction += 360;
}


Was This Post Helpful? 0
  • +
  • -

#4 acidfire00  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-October 12

Re: Need help with decryption program

Posted 09 October 2012 - 12:19 PM

Alright, thanks a ton, slightly confused still about the operator, but I kind of have an idea.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3169
  • View blog
  • Posts: 9,595
  • Joined: 05-May 12

Re: Need help with decryption program

Posted 09 October 2012 - 04:22 PM

Here's one way to test your idea:
for(int i = 0; i < 26 * 2; i++)
{
    printf("i = %d, character = %c\n", i % 26; i + 'A');
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1