RSA Encryption Program with Assembly!!

by SirCalcsALot, Jul 16, 2020, 5:54 PM

Hello everyone!

I thought I would share the RSA encryption program I've mentioned in a previous post. It is written in ARM assembly and can process RSA encryption of up 400 bits, with a max 31 bit key length. Because of the short key length, it is very unsecure and can be easily hacked with something like Wolfram Alpha. I designed this code as a final project for my engineering class on microprocessors and assembly language.

Here are a few things about the code:
  • Assembly uses something called registers to manipulate data. We have 12 registers we can use that act as our twelve possible variables. Each register can hold a maximum of 32 bits, so in some places I needed two registers to work with 64 bit numbers.
  • Since we only have 12 variables, sometimes we have to push data into the stack to save it for later when we need to access it again.
  • The version of ARM assembly I was using doesn't have a moduluo operator, so I had to implement my own.
  • To perform the operation $a^b \mod c$, I implemented a semi-fast algorithm. Initially I used a recursive approach, but I had to switch to an iterative approach due to memory constraints.

I've attached the report I wrote up to submit for my project (I had to split it into pieces because of the max file limit on AoPS). The report talks a bit more about the algorithms used as well as shows some test cases. If you look carefully, you will notice that I cited Wikipedia in this report since that is were I got one of my algorithms! :o

Since the code is over 100 lines, I've included it in a hide tag. Feel free to ask me any questions about the code or assembly in general. Assembly really takes you down to the lower levels of programming and you need to think about things like
  • How functions work and how do you return something from a function.
  • How lists work (we actually need an address as well as the number of items in the list).
  • How variables work. Some variables point to actual values in memory. Others point to the address in memory that the data is at.

Click to see code

I'll try to answer any question you all might have on assembly, so feel free to ask if you want to know about something. Enjoy the code! :D

(Since I could only attach three files, the first appendix with the code is here and the second appendix with a longer test is here. Let me know if you have issues with these links.)
Attachments:
conclusion_referecnes.pdf (230kb)
report_v2_compressed1.pdf (481kb)
report_v1_compressed.pdf (426kb)
This post has been edited 3 times. Last edited by SirCalcsALot, Jul 16, 2020, 6:25 PM

Comment

6 Comments

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Wow, how do you program in assembly? I thought that that was extremely difficult.

(But I write in high-level languages only, so I might be biased.)

by duck_master, Jul 18, 2020, 3:11 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
It's not as hard as it looks, and it's actually sort of fun once you know the basics.

by SirCalcsALot, Jul 18, 2020, 6:02 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
what language is this?

by ARay10, Jul 20, 2020, 4:46 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
It's one of many different types of Assembly Languages. Since this ARM Assembly, the language is specifically designed for micro-controllers and computers with ARM Architecture.

by SirCalcsALot, Jul 20, 2020, 5:13 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
1.At LoopEm you are finding last bit of R2 right? but you wrote finding last bit of R5,
If this is So, Why moving R4 to R5 ?

2. WHy are you finding remainder for every iteration?, you can find remainder after finding a^b

by killmonger, Nov 29, 2020, 8:44 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
1. You are correct. I should of wrote "finding the last bit of R2".

2. a^b could be very large, but taking the remainder at each step makes the numbers smaller to fit in a 32 bit register.

by SirCalcsALot, Dec 3, 2020, 4:23 AM

This is a place for me to put interesting programs and problems (maybe some electrical engineering too!). To see Asymptote codes, use the Asymptote tag.

avatar

SirCalcsALot
Shouts
Submit
  • Wait they were your old classmate
    dang
    also hi SCAL

    by the_mathmagician, Apr 9, 2022, 4:59 PM

  • hello old classmate!

    by RedFlame2112, Nov 10, 2021, 12:17 AM

  • this is the best blog ive ever seen on aops. respect

    by Anaxagoras, Oct 4, 2021, 7:08 PM

  • orz orz orz orz

    by cubingsoda, Aug 3, 2021, 5:27 AM

  • I really like this blog for some reason.

    by AndrewC10, Jul 31, 2021, 4:59 AM

  • who, me?

    by Bachsonata3, Jun 19, 2021, 6:06 PM

  • :O I found you

    by leapftstars, Jun 19, 2021, 6:02 PM

  • can I be contrib? sircalcs pro orz orz orz

    by Bachsonata3, Jun 19, 2021, 5:21 PM

  • One of my favorite helpers :D nice bike btw!

    by AlwaysOnce, May 22, 2021, 3:19 AM

  • sircalcsalot is the best :omighty:

    by pith0n, May 20, 2021, 5:25 AM

  • HELLO!!!!!! :D :D

    by cubingsoda, Apr 15, 2021, 8:00 PM

  • Hello everyone! Nice blog!

    by shadow09, Mar 17, 2021, 2:15 PM

  • @below you got the 100th shout :P

    by player01, Feb 2, 2021, 8:39 PM

  • Hi SirCalcsALot! :-D

    by aops-g5-gethsemanea2, Jan 11, 2021, 12:03 PM

  • Thanks! I'll probably return to my original avatar after the holidays are over.

    by SirCalcsALot, Dec 3, 2020, 11:15 PM

113 shouts
Contributors
Tags
About Owner
  • Posts: 4021
  • Joined: Jun 28, 2014
Blog Stats
  • Blog created: Feb 13, 2015
  • Total entries: 43
  • Total visits: 13624
  • Total comments: 238
Search Blog