Skip to content
International Shipping
Wish Lists Cart
0 items

ASCII Encryption-Decryption Project

27 Nov 2023
ASCII Encryption-Decryption Project

ASCII Games

Do you know that you can automatically decode a text that we have provided as encrypted or automatically encrypt a text by utilizing the ASCII character table using PicoBricks and MicroBlocks IDE? ASCII (which stands for American Standard Code for Information Interchange) is a character encoding standard for text files on computers and other devices. Each time you click the PicoBricks button after entering the text you want to encrypt into the code, the equivalent ASCII table of the letters in the text you want to encrypt will appear. Once a 3-second countdown, the encrypted form of the text will show on both the PicoBricks OLED screen and the MicroBlocks blocks once you have seen the numerical equivalents of all the characters in the text you want to encrypt in the ASCII table.

Details and Algorithm

This algorithm, implemented in PicoBricks and MicroBlocks IDE, converts a given input text into its corresponding ASCII values, displaying these values one by one on the PicoBricks screen. After obtaining all the ASCII values, it applies an unspecified encryption method to transform them into an encrypted version of the text. This encrypted result is then displayed on both the PicoBricks OLED screen and the MicroBlocks blocks. A 3-second countdown may be included for user feedback. It's important to note that the specific encryption technique used is not detailed, and this project is more of an educational exercise than a secure encryption solution. 

Components

1xPicobricks

Wiring Diagram

ascii games

You can use the following MicroBlocks code to encrypt any text you want with PicoBricks by using the ASCII table.

After specifying the text you want to encrypt in the code, each tiem you click the PicoBricks button, you will see the equivalent in ASCII table of letters in the text you want to encrypt in order. After seeing the numerical equivalent of all the characters in the text you want to encrypt in the ASCII table, the encrypted version of the text will appear on both the PicoBricks OLED screen and the MicroBlocks blocks after a 3-second countdown.

MicroBlocks Code of The ASCII Encryption

MicroBlocks Code of The ASCII Encryption

ASCII Decryption With PicoBricks IDE

With PicoBricks, we can decrypt a given encrypted text by using the ASCII table. For this, you can create the code blocks below and print the encrypted text you specified in the code on the OLED screen of PicoBricks.

MicroBlocks Code of The ASCII Decryption

MicroPython Codes for Encryption of the PicoBricks


from time import sleep
import machine
from machine import Pin
from machine import I2C
from picobricks import SSD1306_I2C
import time

pin_button = machine.Pin(10, machine.Pin.IN)
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=200000)
oled = SSD1306_I2C(128, 64, i2c, addr=0x3c)

c = "PicoBricks"
encryption_char = len(c)
count = 0
empty = []
while True:
    if pin_button.value():
        oled.fill(0)
        oled.text("{}".format([ord(text) for text in c[count]]), 0, 0)
        oled.show()
        empty.insert(count,[ord(text) for text in c[count]])
        count += 1
        time.sleep((0.3))
        oled.show()
        while count == encryption_char:
            oled.fill(0)
            oled.text("{}".format("Encryption "), 0, 0)
            oled.text("{}".format("Complete..."), 0, 8)
            oled.text("{}".format(empty[0]), 0, 16)
            oled.text("{}".format(empty[1]), 45, 16)
            oled.text("{}".format(empty[2]), 90, 16)
            oled.text("{}".format(empty[3]), 0, 24)
            oled.text("{}".format(empty[4]), 45, 24)
            oled.text("{}".format(empty[5]), 90, 24)
            oled.text("{}".format(empty[6]), 0, 32)
            oled.text("{}".format(empty[7]), 45, 32)
            oled.text("{}".format(empty[8]), 90, 32)
            oled.text("{}".format(empty[9]), 0, 40)
            oled.show()

Decryption Microphyton Codes


from time import sleep
import machine
from machine import Pin
from machine import I2C
from picobricks import SSD1306_I2C
import time

pin_button = machine.Pin(10, machine.Pin.IN)
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=200000)
oled = SSD1306_I2C(128, 64, i2c, addr=0x3c)

c = [80, 105, 99, 111, 66, 114, 105, 99, 107, 115]
while True:
    if pin_button.value():
        for i in range((10)):
            oled.fill(0)
            oled.text("{}".format(chr(c[i])), 45, 30)
            oled.show()
            time.sleep((0.5))

Arduino IDE Codes


#ifndef ACROBOTIC_SSD1306_H
#define ACROBOTIC_SSD1306_H

#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#ifdef __AVR__
  #include <avr/pgmspace.h>
  #define OLEDFONT(name) static const uint8_t __attribute__ ((progmem)) name[]
#elif defined(ESP8266)
  #include <pgmspace.h>
  #define OLEDFONT(name) static const uint8_t name[]
#else
  #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
  #define OLEDFONT(name) static const uint8_t name[]
#endif

#include "Wire.h"
#include "fonts/font8x8.h"
#include "fonts/font5x7.h"

// Default screen size is 128x64. Using a #define in your sketch before
// the #include statement can change the default size.

#if !defined SSD1306_128_64 && !defined SSD1306_128_32
  #define SSD1306_128_64
#endif

#if defined SSD1306_128_64
  #define SSD1306_Max_X                 127
  #define SSD1306_Max_Y                 63
#endif
#if defined SSD1306_128_32
  #define SSD1306_Max_X                 127
  #define SSD1306_Max_Y                 31
#endif

#define PAGE_MODE                     01
#define HORIZONTAL_MODE               02

#define SSD1306_Address               0x3C
#define SSD1306_Command_Mode          0x80
#define SSD1306_Data_Mode             0x40
#define SSD1306_Display_Off_Cmd       0xAE
#define SSD1306_Display_On_Cmd        0xAF
#define SSD1306_Normal_Display_Cmd    0xA6
#define SSD1306_Inverse_Display_Cmd   0xA7
#define SSD1306_Activate_Scroll_Cmd   0x2F
#define SSD1306_Dectivate_Scroll_Cmd  0x2E
#define SSD1306_Set_Brightness_Cmd    0x81

#define Scroll_Left                   0x00
#define Scroll_Right                  0x01

#define Scroll_2Frames                0x7
#define Scroll_3Frames                0x4
#define Scroll_4Frames                0x5
#define Scroll_5Frames                0x0
#define Scroll_25Frames               0x6
#define Scroll_64Frames               0x1
#define Scroll_128Frames              0x2
#define Scroll_256Frames              0x3

class ACROBOTIC_SSD1306 {
  public:
    char addressingMode;
    void init(TwoWire& wire=Wire);

    void setNormalDisplay();
    void setInverseDisplay();

    void sendCommand(unsigned char command);
    void sendData(unsigned char Data);

    void setPageMode();
    void setHorizontalMode();

    void setTextXY(unsigned char Row, unsigned char Column);
    void clearDisplay();
    void setBrightness(unsigned char Brightness);
    bool putChar(unsigned char c);
    void putString(const char *string);
    void putString(String string);
    unsigned char putNumber(long n);
    unsigned char putFloat(float floatNumber,unsigned char decimal);
    unsigned char putFloat(float floatNumber);
    void drawBitmap(unsigned char *bitmaparray,int bytes);

    void setHorizontalScrollProperties(
        bool direction,
        unsigned char startPage,
        unsigned char endPage,
        unsigned char scrollSpeed);
    void activateScroll();
    void deactivateScroll();

    void displayOn();
    void displayOff();

    void setFont(const uint8_t* font, bool inverse=false);

  private:
    const uint8_t* m_font;      // Current font.
    uint8_t m_font_offset = 2;  // Font bytes for meta data.
    uint8_t m_font_width;       // Font witdth.
    uint8_t m_col;              // Cursor column.
    uint8_t m_row;              // Cursor row (RAM).
    bool m_inverse=false;       // Inverse text.
    TwoWire* m_wire;
};

extern ACROBOTIC_SSD1306 oled;  // ACROBOTIC_SSD1306 object

#endif
Prev Post
Next Post

Thanks for subscribing!

This email has been registered!

Shop the look
Choose Options

Edit Option

Have Questions?

Back In Stock Notification

Compare

Product SKURatingDescription Collection Availability Product Type Other Details
this is just a warning
Login
Shopping Cart
0 items