A Basic RSA Encrypter

This is a small post about implementing a basic RSA encrypter to encrypt sections in an exe. We can use this to exchange exes with people. We will encrypt the section using the public key and the user has to use his private key to decrypt the exe. This can be applied in evading anti-viruses too.

I will use multiplication instead of an exponent. Since it would be easy to implement in few lines in assembly. However, this will allow breaking the private key easily hence the complete scheme is broken.

Enc = (m*e) \text{ mod } N

Dec = (c*d) \text{ mod } N

The correctness of this scheme depends on the fact that

Dec(Enc(m)) = (m*e*d) \text{ mod } N = m \text{ mod } N

For this example let’s take 3 as the public key and 171 as the private key.

Enc = m * 3 \text{ mod } 256

Dec= c * 171 \text{ mod } 256

Here’s a simple assembly implementation. Since we are using modulus 256 the first byte is removed out from the value. So we don’t need to again implement a modulus in the code.

mov ebx, start of section
mov al, byte [ebx]
mov cl, K ; key goes here
mul cl
mov byte ptr [ebx],al
inc ebx
cmp ebx, end of section
jle short @loop

I made a small video demonstration.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s