reversing the Mod operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Candace

    #1

    reversing the Mod operator

    I am writing an encryption program that takes a digit and yields its modulus.
    For example, 7 Mod 4 yields 3. How can I reverse this procedure and get the
    original digit back in order to write a decryption program?
  • Josip Medved

    #2
    Re: reversing the Mod operator

    On Oct 13, 9:44 pm, Candace <Cand...@discus sions.microsoft .comwrote:
    I am writing an encryption program that takes a digit and yields its modulus.
    For example, 7 Mod 4 yields 3. How can I reverse this procedure and get the
    original digit back in order to write a decryption program?
    Since there can be same result for multiple numbers (e.g. 7 MOD 4 = 3
    and 3 MOD 4 = 3) there is no way.

    BTW. Why would you even consider this? You have lots of crypting
    algorithms already available that do good job.

    --
    Greetings,
    Josip Medved
    A personal website dedicated to technology, software development, and practical tools.


    Comment

    • Candace

      #3
      RE: reversing the Mod operator

      This is for a class that I am taking. I'm just learning to program. The
      instructions said "Your program should read a four-digit Integer entered by
      the user and encrypt it as follows: Replace each digit by (the sum of that
      digit and 7) modulo 10. Then write a program that inputs an encryption
      four-digit Integer and decrypts it to form the original number." Do you think
      I could be miss-understanding the instructions? Or are you reading it as the
      same meaning that I am?

      "Candace" wrote:
      I am writing an encryption program that takes a digit and yields its modulus.
      For example, 7 Mod 4 yields 3. How can I reverse this procedure and get the
      original digit back in order to write a decryption program?

      Comment

      • Miro

        #4
        Re: reversing the Mod operator

        I agree, for crypting.

        Take a look at the post by "IZZY" about 128 bit encryption function he
        posted.

        Search this newsgroup for
        Variable = EncryptString12 8Bit(txt_Passwo rd.Text, EncryptionKey)

        Miro


        "Josip Medved" <jmedved@jmedve d.comwrote in message
        news:1160769083 .388745.175500@ b28g2000cwb.goo glegroups.com.. .
        On Oct 13, 9:44 pm, Candace <Cand...@discus sions.microsoft .comwrote:
        >I am writing an encryption program that takes a digit and yields its
        >modulus.
        >For example, 7 Mod 4 yields 3. How can I reverse this procedure and get
        >the
        >original digit back in order to write a decryption program?
        >
        Since there can be same result for multiple numbers (e.g. 7 MOD 4 = 3
        and 3 MOD 4 = 3) there is no way.
        >
        BTW. Why would you even consider this? You have lots of crypting
        algorithms already available that do good job.
        >
        --
        Greetings,
        Josip Medved
        A personal website dedicated to technology, software development, and practical tools.

        >

        Comment

        • teslar91@hotmail.com

          #5
          Re: reversing the Mod operator

          Candace wrote:
          This is for a class that I am taking. I'm just learning to program. The
          instructions said "Your program should read a four-digit Integer entered by
          the user and encrypt it as follows: Replace each digit by (the sum of that
          digit and 7) modulo 10. Then write a program that inputs an encryption
          four-digit Integer and decrypts it to form the original number." Do you think
          I could be miss-understanding the instructions? Or are you reading it as the
          same meaning that I am?
          Try looking at the problem a little differently, and I think you'll get
          it.

          What Mod 10 actually does to a whole number is remove everything except
          the rightmost digit, right?

          Suppose your original digit is 5. You have to add 7. Try incrementing
          5 by 1, seven times, in your head - but remember, you can never reach
          double digits. When you pass nine, start back at zero. 5 becomes 6,
          7, 8, 9, 0, 1, 2. So 2 is your encrypted version of 5.

          To decrypt: 2 becomes 1, 0, 9, 8, 7, 6, 5.

          Now see if you can find a mathematical way to decrypt a single digit in
          *one* line of code. If you can't, I'll tell you - but you learn more
          this way; gotta exercise the brain to get really good at this stuff. :)

          Comment

          • Göran Andersson

            #6
            Re: reversing the Mod operator

            I see. This is a classic Caesar encryption, a method that is more than
            2000 years old. :)

            The encryption works by shifting the alphabet a certain number of steps,
            for example using a shift of +1 would turn "BAR" into "CBS". To decrypt
            you simply use the negative shift, i.e. the shift -1 turns "CBS" into "BAR".

            The characters that are shifted outside of the alphabet just wraps over
            at the other end, that's where the modulo comes in.

            With this lesson of history and cryptography, I hope that you understand
            what your program is actually supposed to be doing, only using digits
            instead of letters. :)

            Candace wrote:
            This is for a class that I am taking. I'm just learning to program. The
            instructions said "Your program should read a four-digit Integer entered by
            the user and encrypt it as follows: Replace each digit by (the sum of that
            digit and 7) modulo 10. Then write a program that inputs an encryption
            four-digit Integer and decrypts it to form the original number." Do you think
            I could be miss-understanding the instructions? Or are you reading it as the
            same meaning that I am?
            >
            "Candace" wrote:
            >
            >I am writing an encryption program that takes a digit and yields its modulus.
            >For example, 7 Mod 4 yields 3. How can I reverse this procedure and get the
            >original digit back in order to write a decryption program?

            Comment

            Working...