GMP RSA implementation

This is a discussion on GMP RSA implementation within the C++ Programming forums, part of the General Programming Boards category; I'm trying to implement the RSA algorithm (just for fun, with no padding). My code works fine encrypting up to ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    19

    GMP RSA implementation

    I'm trying to implement the RSA algorithm (just for fun, with no padding). My code works fine encrypting up to 83 characters but after this the decryption output is only gibberish and (no matter the size of the input) the output is always 83 bits. Anyone have any idea what's going on here?

    Basic encryption procedure:

    1.) Take plaintext and concatenate each hex ascii value to form an integer representation of the text. Each hex value will be two digits.
    2.) Encrypt this number.

    Decryption:
    1.) Take ciphertext and decrypt.
    2.) Take decrypted number, convert to hex and split up into pairs of digits (i.e. one hex value) and convert to ascii character.

    http://pastebin.com/7BtjVQ6n

    Any help most appreciated!

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Could it have something to do with the size of your key? Since the calculation is mod PKn1 it obviously can't properly encode a message whose value is greater than PKn1.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    19
    Quote Originally Posted by oogabooga View Post
    Could it have something to do with the size of your key? Since the calculation is mod PKn1 it obviously can't properly encode a message whose value is greater than PKn1.
    Ah, of course.

    Do you have any ideas about the best way of splitting up the message into chunks <n ?

    Thanks!

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,170
    A typical approach is to use RSA to encrypt a key for symmetric encryption, then the splitting of the plaintext is done as per the normal methods of block (or stream) encryption, e.g., by using an IV with CBC.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using C++ within C implementation
    By onako in forum C Programming
    Replies: 16
    Last Post: 10-31-2011, 03:12 PM
  2. Replies: 7
    Last Post: 10-01-2008, 08:45 PM
  3. C and implementation
    By Troll_King in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 09-04-2002, 09:00 AM
  4. help with implementation
    By NANO in forum C++ Programming
    Replies: 14
    Last Post: 04-30-2002, 02:09 PM
  5. implementation?
    By calQlaterb in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21