RSA Encryption
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: RSA Encryption

  1. #1
    Join Date
    Apr 2010
    Posts
    8

    RSA Encryption

    I am not very comfortable with using C++ but am very familiar with Java. I am trying to construct an RSA encryption. The issue I am running into is when numbers get large. I am currently using uint64_t for all of my numbers, but at one point the numbers get too big and my final answer is different than what it should be.
    Another issue is converting text into ascii. I want it so that if I type 'a', it would convert to 97.

    Thank you very much for the help
    Dennis

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: RSA Encryption

    You'll have to get yourself a BigInt library of some kind. They're less efficient than built-in types, but have a larger dynamic range. There are several available, Google it.

    As far as converting to ASCII----simply recognize that char is an integer type. If you read in the character 'a' to a char (or as part of a string made up of chars), then that char will have the value 97, and you can see this if you cast it to int on output.

    This only gets slightly tricky when dealing with digits, since then the type you're reading it to determines the value you get. If you enter "5", for instance, then if you were doing cin >> intval you'd get inval with the value 5; but if you did cin >> charval, you'd get charval with the value 53 ('5').

  3. #3
    Join Date
    Feb 2005
    Posts
    2,160

    Re: RSA Encryption

    There're probably dozens of C++ RSA implementations already "turn-key" and MS VC++ has the CryptoAPI which supports RSA, so, unless this is purely academic, why re-invent the wheel?

  4. #4
    Join Date
    Apr 2010
    Posts
    8

    Re: RSA Encryption

    This is for a class project so yeah, I'm stuck doing it.

    I am having issues with the bigint class. I'm not 100% how to set it up and then how to declare a variable as a BigInt.

    Thanks,
    Dennis

  5. #5
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,281

    Re: RSA Encryption

    Quote Originally Posted by gberg927 View Post
    This is for a class project so yeah, I'm stuck doing it.

    I am having issues with the bigint class. I'm not 100% how to set it up and then how to declare a variable as a BigInt.

    Thanks,
    Dennis
    Just because it is for class doesn't mean you have to reinvent each and every line of code. I'm sure your teacher would rather have you concentrate on the RSA part than the BigInt part.

    2 things though:
    1 - Are the numbers you are manipulating so big as to need BigInts? With RSA, the answer is usually yes, but since this is also a class project, you can get away with using little keys. See with your professor if he expects you to actually use bigints, and if the answer is yes, do you have to code it yourself.

    2 - Also, by reordering operations in a smart way, you can get the same result, but use smaller bounds in your intermediate operations. A typical example is when calculating a combination.

  6. #6
    Join Date
    Apr 2010
    Posts
    8

    Re: RSA Encryption

    Yeah, I have already asked my teacher if we can do a "mini RSA" project. She said that she would consider our project weaker even though some kids in my class projects are jokes. She said it is fine to use BigInt classes and that it is mot likely needed. My issue comes because I have no idea how the BigInt class works. The one I acquired gave me bigint.h, bigint.cpp and main.cpp. I'm not sure what to do with these files and how to use them in my function.

    I appreciate any help because I cannot seem to find information anywhere,
    Thanks,
    Dennis

  7. #7
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,249

    Re: RSA Encryption

    Quote Originally Posted by gberg927
    My issue comes because I have no idea how the BigInt class works. The one I acquired gave me bigint.h, bigint.cpp and main.cpp. I'm not sure what to do with these files and how to use them in my function.
    You might want to look into using the GMP; the documentation is not bad, and a not-so-naive C++ wrapper is provided.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  8. #8
    Join Date
    Jan 2009
    Posts
    1,689

    Re: RSA Encryption

    Ask your professor, I'm sure that he/she wouldn't assign a beginner C++ course something that requires ints larger than 64 bit.

    Is this the bigint library that you're using? http://mattmccutchen.net/bigint/
    That's the one that I always used, its much easier to use than GMP, but also much slower.

  9. #9
    Join Date
    Apr 2010
    Posts
    8

    Re: RSA Encryption

    Unfortunatly this isn't a C++ course. It is a network security class so my knowledge of C++ does not matter. My group members believed programming in C++ would be a good idea. I have gotten that Big Integer Library but am not sure how to actually utilize it. I am using Eclipse IDE and MINIGW compiler. How can I use this library with these two?

    Thanks again,
    Dennis

  10. #10
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: RSA Encryption

    There are usually two steps to using a library:
    1) #include the relevant header files from it
    2) Link against the relevant lib files from it, building the library first if necessary (it will come with a Makefile or VS project if that's the case)

    For some "header-only" libraries, you don't need to do #2.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center