C++ help?

Discussion in 'OT Technology' started by knucks, Mar 12, 2010.

  1. knucks

    knucks Active Member

    Joined:
    Jul 14, 2004
    Messages:
    18,512
    Likes Received:
    1
    Location:
    734
    I'm working on a decryption program. Basically it goes like this:

    Checks for % or @, which determine whether it goes up in ASCII table or down.
    Also checks for a digit following % or @, and applies a shift based on the direction (up/down) and the digit.

    If @ or % is without trailing digit, it must error to a certain code.

    If ^ is present, that alters the ongoing shift (adds to it), so if somewhere at beginning it was @2 then text then ^3, the shift becomes in essence @6 after the ^. If no digit is after ^, then error.

    It can be single+ digits.



    http://pastebin.com/QWfzsKN2
     
    Last edited: Mar 14, 2010
  2. CodeX

    CodeX Guest

    I'll check it out when I get home from work.

    Clarify something for me though...

    If you had: @3abc^3def
    You would get: defjkl

    Assuming @ meant increase, correct?
     
  3. knucks

    knucks Active Member

    Joined:
    Jul 14, 2004
    Messages:
    18,512
    Likes Received:
    1
    Location:
    734
    If @ meant increase, yes that's correct.

    But read this:


    @ means shift downward, towards A. If it goes below A, it goes to Z Y X etc..
    If you had:

    @3abc^3def

    output:XYZXYZ

    Here's some sample input/output they gave me:
    input:
    @25CNM'S OZX ZMX ZSSDMSHNM SN SGD LZM ADGHMC SGD BTQSZHM.

    output:

    DON'T PAY ANY ATTENTION TO THE MAN BEHIND THE CURTAIN.
     
  4. knucks

    knucks Active Member

    Joined:
    Jul 14, 2004
    Messages:
    18,512
    Likes Received:
    1
    Location:
    734
    made some progress with the code. still have to implement the ^ and to print error code if no digits follow % or @
     
  5. CodeX

    CodeX Guest

    At first glance, you aren't accounting for 2 digit shifts properly, this part of the code takes the 2 in the example you gave me and sets it correctly, but then when it reads the 5 it replaces the value of 2 in the "shift" variable with the value of 5.

    Instead, what you need to do is multiply the first value by 10 and then add the second.

    Code:
    else if(isdigit(ch) && ch >= '0' && ch <= '9')    shift = resetShift(ch, firstShift);
    
    int resetShift(char ch, int firstShift)
    {
        int shift = (ch - '0') * firstShift;
        return shift ? shift : 1;
    }
    
    
    The "shift = resetShift(ch, firstShift);" part just overwrites the first digit found with the second...
     
  6. knucks

    knucks Active Member

    Joined:
    Jul 14, 2004
    Messages:
    18,512
    Likes Received:
    1
    Location:
    734
    please see the revised code. i fixed that portion.
     
  7. CodeX

    CodeX Guest

    cool, let me know if you have any other trouble with it.
     
  8. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    sup bro. broly programming crew? get at me bro
     
  9. knucks

    knucks Active Member

    Joined:
    Jul 14, 2004
    Messages:
    18,512
    Likes Received:
    1
    Location:
    734
    any ideas on how to get it to error when there is no digit present after % or @ or ^ ?
     
  10. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    where at in the file?
     
  11. knucks

    knucks Active Member

    Joined:
    Jul 14, 2004
    Messages:
    18,512
    Likes Received:
    1
    Location:
    734
    YO GOGZ, ok check the new pastebin link: http://pastebin.com/QWfzsKN2


    i sort of have it working to error if there is no 'digit' (0-9, inclusive) after % or @ or ^, but i need it to error and then stop reading the characters until a '#'

    Here's the sample input and sample output:


    %20ZXAYZ SK @ EUA YNUARJT'Z HK NKXK.#

    TRUST ME *** Error Code 2 -- No shift value as expected ***
     
    Last edited: Mar 14, 2010

Share This Page