Thread: GMP RSA implementation

  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
    28,412
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 02:12 PM
  2. Replies: 7
    Last Post: 10-01-2008, 07:45 PM
  3. C and implementation
    By Troll_King in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 09-04-2002, 08:00 AM
  4. help with implementation
    By NANO in forum C++ Programming
    Replies: 14
    Last Post: 04-30-2002, 01:09 PM
  5. implementation?
    By calQlaterb in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:25 AM