Thread: How to handle 1024 bits at a time

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    3

    Question How to handle 1024 bits at a time

    To design RSA Encryption algorithm I need a variable which can hold 1024 bits .

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
    #include <limits.h>
    unsigned char foo[ 1024 / CHAR_BIT ];
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    _Bool foo[1024]; /* C99 ;) */
    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >_Bool foo[1024]; /* C99 */
    This is misleading because it implies that _Bool can be less than sizeof(char) (which it can't in a conforming implementation).
    My best code is written with the delete key.

  5. #5
    .
    Join Date
    Nov 2003
    Posts
    307
    As another point of view - look for a bignum library which will handle arbitrary length integers and floating point operations.

    try:

    http://swox.com/gmp/

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Prelude
    >_Bool foo[1024]; /* C99 */
    This is misleading because it implies that _Bool can be less than sizeof(char) (which it can't in a conforming implementation).
    Possibly, however, they wanted to store "1024 bits", and that would in fact give you the required 1024 "bits". Bits have one of two states, and oddly enough, so do _Bools. I never said it would be the best way to do it. As a matter of fact, it would be an absolute pain in the ass to work with. But it could be done.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    .
    Join Date
    Nov 2003
    Posts
    307
    As another aside - why are you writing RSA code? If it's a school assignment, okay.
    If it is for production code, look for a tested library module. Encryption is not something you throw together and expect protection. Even tho the RSA math is pretty easy.

    How do you plan to generate keys? - for example. I cannot begin to describe what an awful idea it is to push your code into any kind of production environment. Just don't do it.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >they wanted to store "1024 bits"
    That's why I didn't dispute that it works. However, if they wanted an array of only 1024 bits, the logical error could be easily missed. There are already enough "language experts" ..........ing about C being obtuse without our help.
    My best code is written with the delete key.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > As another aside - why are you writing RSA code?
    I agree, not knowing how to even represent a basic crypto datatype is off to a bad start.

    RSA may be "secure", but it can only be as secure as it's implementation. If that's buggy and leaks information, then all is lost even it it technically passes all the algorithmic tests.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. SDLKey to ASCII without unicode support?
    By zacs7 in forum Game Programming
    Replies: 6
    Last Post: 10-07-2007, 03:03 AM
  3. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 07:56 AM
  4. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  5. relating date....
    By Prakash in forum C Programming
    Replies: 3
    Last Post: 09-19-2001, 09:08 AM