Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Overflow Exception

Overflow Exception

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pabloraul
    wrote on last edited by
    #1

    Is there anyway to get this expression to work without getting an overflow execption? Answer = (PublicKeyB^PrivateKeyA)Mod(PublicKeyA) the public and private keys are supposed to be 9 digit numbers example: 123456789 i've tryed using System.Math.Pow but it uses Doubles and thats the source of the overflow anyway, i would like to know if its posible and if it is, how?

    G G 2 Replies Last reply
    0
    • P pabloraul

      Is there anyway to get this expression to work without getting an overflow execption? Answer = (PublicKeyB^PrivateKeyA)Mod(PublicKeyA) the public and private keys are supposed to be 9 digit numbers example: 123456789 i've tryed using System.Math.Pow but it uses Doubles and thats the source of the overflow anyway, i would like to know if its posible and if it is, how?

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      As you are using the Mod operator, I think that you mean the VB meaning of the ^ operator. In C# the ^ operator means an exclusive or, and doesn't cause an overflow. One nine digit number to the power of another nine digit number is way too large to fit in any integer type (unless you have a 32000000000 bit integer laying around...). It's even way too large to fit in a double or a decimal. What is it that you try to accomplish with this calculation? It doesn't really make any sense.

      Despite everything, the person most likely to be fooling you next is yourself.

      P 1 Reply Last reply
      0
      • G Guffa

        As you are using the Mod operator, I think that you mean the VB meaning of the ^ operator. In C# the ^ operator means an exclusive or, and doesn't cause an overflow. One nine digit number to the power of another nine digit number is way too large to fit in any integer type (unless you have a 32000000000 bit integer laying around...). It's even way too large to fit in a double or a decimal. What is it that you try to accomplish with this calculation? It doesn't really make any sense.

        Despite everything, the person most likely to be fooling you next is yourself.

        P Offline
        P Offline
        pabloraul
        wrote on last edited by
        #3

        the formula i wrote there is not any kind of code, it is written in human language, i know for ^ i should use Pow(base,exponent) and for Modulus i should use %; it is supposed to be a formula to calculate a value in order to calculate another value to prove the basis of cryptography to my teacher in classroom. (it is supposed to be somehting simple) anyway, i just wanted to know if it was possible to do without getting an overflow

        1 Reply Last reply
        0
        • P pabloraul

          Is there anyway to get this expression to work without getting an overflow execption? Answer = (PublicKeyB^PrivateKeyA)Mod(PublicKeyA) the public and private keys are supposed to be 9 digit numbers example: 123456789 i've tryed using System.Math.Pow but it uses Doubles and thats the source of the overflow anyway, i would like to know if its posible and if it is, how?

          G Offline
          G Offline
          GLLNS
          wrote on last edited by
          #4

          I think that the .Net framework 3.0 or 3.5+ ships with a class named BigInteger that can fit your needs. There are a lot of similar free classes available (I beleave at least one in CodeProject and one in the mono project)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups