I'm having a hard time finding out how PlainText becomes Ciphertext. I understand that I do the following: PlainText -> RSA/AES/Whatever -> Ciphertext

Can someone please tell me how this happens, I'm not sure how data (more specifically text) becomes this when using RSA, which uses primes to generate the following output from Test:

Version: GnuPG v2


And how does Test get signed like the signed message below? I know it uses SHA256, but does it then sign the hash with your private key?

Hash: SHA256

Version: GnuPG v2

  • $\begingroup$ Roughly speaking, the message is encoded to a number (which is the plaintext), then it is encrypted, generating another number (a very big one), and finally it is encoded in a text, which is what PGP shows to you. $\endgroup$ Commented Aug 31, 2016 at 20:30

2 Answers 2


You are asking a very generic question: how does plaintext become ciphertext. Well, plaintext is used as input for an encryption function, usually defined as $C = E(K, M)$ or $C = E_K(M)$ where $E$ is the encryption function, $K$ is the key, $M$ is the message or plaintext and $C$ of course is the ciphertext. So the ciphertext is anything that is output by the encryption function (unless the output is $\perp$, i.e. the input does not conform to the requirements).

You've defined a string "Test" as input, but modern ciphers operate on bytes. This means that "Test" first has to be encoded into a byte array. This is performed using a character encoding such as UTF-8.

PGP however defines an entire protocol and container format. Instead of just outputting the ciphertext itself it defines a packet based container format which specifies the key and algorithm used, etc. This protocol and container format are specified in RFC 4880: OpenPGP Message Format. That also includes the container of the signature and how it can be calculated.

OpenPGP can use different ciphers. In general though it uses a hybrid cryptosystem where a public key of an asymmetric cipher - such as RSA - encrypts a secret key of a symmetric cipher. That key is then in turn used to encrypt the actual data.

Note that a signature is not called ciphertext, that term is specific to encryption/decryption.


Pulling straight from the wikipedia article on RSA:


Suppose that Bob would like to send message M to Alice.

He first turns M into an integer m, such that 0 ≤ m < n and gcd(m, n) = 1 (that is, m and n are coprime integers) by using an agreed-upon reversible protocol known as a padding scheme. He then computes the ciphertext c, using Alice's public key e, corresponding to

${\displaystyle c\equiv m^{e}{\pmod {n}}}$

This can be done efficiently, even for 500-bit numbers, using modular exponentiation. Bob then transmits c to Alice.


Alice can recover m from c by using her private key exponent d by computing

${\displaystyle c^{d}\equiv (m^{e})^{d}\equiv m{\pmod {n}}} {\displaystyle c^{d}\equiv > (m^{e})^{d}\equiv m{\pmod {n}}}$

Given m, she can recover the original message M by reversing the padding scheme.

Put very simply:

  • encode the message as a number
  • raise the number to a power
  • reduce the larger number obtained this way by dividing it with the RSA modulus and taking the remainder

That's it, as far as the actual act of encryption goes.

The original number you raised to the power and reduced can be recovered by exploiting some mathematical relationship, based on the structure of the modulus. The person who formed the modulus generally does not share the structure with anyone else, and so will be the only person that can invert the ciphertext back to your original message. Also, this means that you cannot simply do this trick with an arbitrary number for the modulus, it must fulfill certain criteria.

Note that this is only how RSA encryption works, and is totally, completely unrelated to how symmetric algorithms like AES function, and that should be asked in a separate question. Your question about RSA signatures appears to already have an answer here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.