Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My C# console application generates very, very large numbers. Up to now I have been able to get past with using the string form of them but now I need them to be integers for what I need to do. The only problem is that they are very big and I mean big (in excess of 500 characters and will most likely be in the thousands when I use it for the purpose it is intended for) and I need the numbers to be added to integers not strings as the number is generated. Is there an integer big enough to hold hundreds and hundreds of characters? If so, please could someone help me do it. They must be integers. Thank you.
Posted
Comments
Richard C Bishop 18-Oct-13 12:12pm    
I doubt it man. A long is the biggest and has a range of +- 9 quintillion. That is only 19 characters with a gigantic number.
Sergey Alexandrovich Kryukov 18-Oct-13 12:17pm    
Please define what is "huge", exactly. The purpose? I'm just curious. Solution 1 is really the solution, anyway.
—SA
Henry Hunt 18-Oct-13 12:23pm    
By huge I mean hundreds or thousands of characters and the purpose is that the number is a sequence of characters from encryption I have made where it converts inputted characters to their ascii codes and does some other stuff with it to make it 'secure'. I know it sounds like a crazy idea and that it could be cracked maybe quite easily but still...
Sergey Alexandrovich Kryukov 18-Oct-13 12:28pm    
Do you mean you want to use one huge integer instead of data (keys, encrypted data, decrypted data)? Is it your won encryption algorithm based essentially on integer arithmetic?

What "ASCII codes", who use them, ever?! Be serious. In encryption, everything is operated on arrays of bytes, nothing else. And ASCII is basically dead, only used in legacy... And irrelevant...
—SA

There is the BigInteger structure[^] in .NET 4.0 and above which will work with integers of any size, up to available memory.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Oct-13 12:18pm    
Of course, a 5.
—SA
Henry Hunt 18-Oct-13 12:19pm    
Thank you I will have a go at that. It is annoying because I don't actually need the number to do any maths on, I only need it to stand in as a very, very long sequence of numbers.
Sergey Alexandrovich Kryukov 18-Oct-13 12:31pm    
Okay, I got it. You answered my question I just asked in my comment to the question. Please see.
Here is my answer: you are going in a wrong way.
—SA
Sergey Alexandrovich Kryukov 18-Oct-13 12:40pm    
Okay, I added Solution 2, please see.
—SA
Thomas Daniels 18-Oct-13 12:24pm    
+5!
Thank you for the clarification. I got it: you are going in a wrong way.

If you really needed some integer arithmetic for your own encryption algorithm, you would really need some big integer objects. Actually, under the hood, encryption algorithms use them. ([EDIT] No, I don't mean this exact structure is use: cryptography algorithm implementations are usually native, not .NET. [END EDIT]) But these big integers are much, much less then those you want to have. If you tried similar (or any, for this matter) encryption algorithms with the integer sizes you wanted, they would work, but with prohibitively low performance. Besides, chances are, you could come across some situations when intermediate calculation result would occupy all available computer memory. With BigInteger, this is not easy but very easy.

As you say you don't need this arithmetic, it makes you request totally pointless. On the public side of all cryptography algorithms, all data, with no exclusions, it represented as byte[] arrays.

And you need to learn how to abstract all that text encoding issued for data processing like cryptography. For that, you just need to understand how encoding works, and learn about Unicode, in particular. Just for the hints:
http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx[^],
http://en.wikipedia.org/wiki/Unicode[^],
http://unicode.org/[^].

Don't mix them up.

[EDIT]

HenryHunt wrote:
What I am trying to do is when someone signs in or fills in details to request an account it encrypts the entered data and sends it using WCF to another computer containing a database of accounts which it then decrypts the sent data…
Okay, but there is nothing special here. You need to use available encryption, more exactly, public-key cryptography:
http://en.wikipedia.org/wiki/Public-key_cryptography[^].

You need to learn thoroughly why it works. The idea is: the server part should generate a key pair for each request and send the user a key for encryption. If this key is eavesdropped, someone else can only encrypt, but not decrypt, because it is done with a private key only stored on the server, never published. On next state, client encrypts the message and sends it. (Some kind of identification token can be used.) If it was HTTPS, you could use what is already supplied with an HTTP server (TLS), plus digital signing with the certificate, always on server, optionally on client. Please see:
http://en.wikipedia.org/wiki/HTTPS[^],
http://en.wikipedia.org/wiki/Transport_Layer_Security[^],
http://en.wikipedia.org/wiki/Digital_signature[^],
http://en.wikipedia.org/wiki/Digital_certificate[^],
http://en.wikipedia.org/wiki/Certificate_authority[^].

But you can do it all by yourself in a custom server.

Also, it's important to understand that, if you also need password protection, you should understand that 1) a password should not be stored anywhere (it's absolutely not needed for authentication and would violate at least privacy), 2) you would not need encryption, as cryptographic hash function can be used. Please see my past answers:
i already encrypt my password but when i log in it gives me an error. how can decrypte it[^],
TCP Connection with username and password[^],
Decryption of Encrypted Password[^],
storing password value int sql server with secure way[^].

And you already have all algorithm implementations in .NET FCL, in particular:
http://msdn.microsoft.com/en-us/library/system.security.cryptography.asymmetricalgorithm%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.aspx[^].

—SA
 
Share this answer
 
v3
Comments
Henry Hunt 18-Oct-13 12:55pm    
ah ok...What I am trying to do is when someone signs in or fills in details to request an account it encrypts the entered data and sends it using WCF to another computer containing a database of accounts which it then decrypts the sent data and cross matches it with the database to get a correct login and then sends a message back saying it can log in. Just to make sure you know what context I want to use the encryption in. Another thing: I am amazed at how much knowledge you have about not just C# but lots of other languages and computers and encryption and a lot about everything to do with computer programming. Where and how have you got it all from?!
Sergey Alexandrovich Kryukov 18-Oct-13 14:00pm    
I knew you would understand it.
I hope now my answer is complete — please see the update, after [EDIT].
Please, don't forget to accept the answer formally. Your follow-up questions will be welcome.
—SA
Henry Hunt 19-Oct-13 5:15am    
Thank you, I have accepted it. Just out of interest, would you say that WCF is the right way to go to match login details with a database on another computer when someone logs in or is there a better way?
Sergey Alexandrovich Kryukov 19-Oct-13 18:32pm    
It depends. In most cases, this is a very good way. The only problem could be compatibility with non-.NET software, but this problem can be solved. Anyway, Microsoft recommends it as the way superior to legacy Web services (SOAP-based, which is of course also supported by WCF) and to "classical" remoting, and the arguments are rather convincing. WCF also provides lower start-up barrier for beginners, at least for most common situations, but I noticed that "classical" .NET remoting can provide more flexibility for trickier requirements. Important benefit of WCF approach is loose coupling and the ease of transparent replacement of the parts of ABC triad (address/binding/Contract)...
—SA
BillWoodruff 19-Oct-13 7:47am    
Wow ! +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900