Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

RISC-V-encryption-algorithms

RISC-V Assembly Ripes UniFi

This repository contains the project developed for the Computer Architecture course (Academic Year 2025/2026) at the University of Florence. The project consists of the implementation of a multilevel encryption and decryption system written entirely in RISC-V Assembly.

General Operation

The program sequentially applies a series of five distinct algorithms to an input text string (myplaintext). The order of application is flexible and specified via a dedicated variable (mycypher). Upon completion of the encryption phase, the program automatically initiates the reverse decryption procedure, restoring the original plaintext.

The logic is entirely centralized within a dual-phase execution cycle ("main-loop"):

  1. Forward Phase (Encryption): The plaintext is progressively encrypted by iterating through the sequence of algorithms from left to right, outputting the partial results to the console.
  2. Reverse Phase (Decryption): The pointer is realigned, and the ciphertext is restored to plaintext by applying the inverse algorithms from right to left.

The Five Ciphers

The system implements the following algorithms, each identified by a specific letter:

  • [A] Substitution (Caesar Cipher): Encryption based on modular arithmetic utilizing a positive or negative integer key (sostK). It shifts alphabet letters forward or backward, managing wrap-around conditions via the modulo operator (% 26) and ignoring numerical digits.
  • [B] Blocks: Encryption utilizing an alphanumeric key with circular shifting (blocKey). It performs the addition of ASCII values and ensures the correct realignment of characters within the printable range.
  • [C] Occurrences: A spatial expansion algorithm. It maps each unique character and associates it with the list of its absolute positions within the string. It utilizes an array to track previously visited characters (seen_chars).
  • [D] Dictionary: Specular transformation of the alphabet (e.g., A to Z, B to Y) and case inversion (uppercase becomes lowercase and vice versa) through algebraic manipulation of ASCII codes. It similarly mirrors numerical digits.
  • [E] Inversion: Completely reverses the string by recursively swapping the first character with the last, utilizing two pointers converging towards the center.

Technical Specifications and Memory Management

  • In-Place Operations: The majority of the algorithms (excluding Occurrences) operate "in-place", directly overwriting the original string in memory to optimize space.
  • Buffer Overflow Prevention: Due to the expansive nature of the occurrences cipher, a dedicated memory buffer buffer_out of 2048 bytes is allocated.
  • Stack and Register Usage: The codebase strictly adheres to RISC-V calling conventions. Registers s0, s1, and s2 are designated for the management of the "main-loop" to minimize memory loads. The stack pointer (sp) is utilized both for preserving return addresses during function calls and as a LIFO data structure for manipulating individual numerical digits during the integer-to-string (itoa) conversion within the occurrences cipher.

Execution and Testing Guidelines

The code was developed to be executed on Linux environments via the Ripes emulator (v2.2.5).

  1. Open Ripes and load the cypher.s file.
  2. Modify the .data section as required to test various configurations
.data
    myplaintext: .string "Progetto Assembly 2026!"
    .zero 2048
    mycypher: .string "ABCDE"   # Order of cipher execution
    sostK: .word -2             # Key for the substitution cipher (A)
    blocKey: .string "OLE"      # Key for the block cipher (B)

About

Simple collection of encryption algorithms in RISC-V using RIPES (v2.2.6)

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages