From e8c190c8b2984cd562ba65890ad86213a13b9e72 Mon Sep 17 00:00:00 2001 From: Crystal Date: Sun, 17 Mar 2024 21:46:44 +0100 Subject: New --- blog/asm/1.html | 74 ++++++++++++++++++++-------------------- blog/c/cherry.html | 82 ++++++++++++++++++++++++++++++++++++--------- src/org/blog/assembly/1.org | 2 +- src/org/blog/c/cherry.org | 36 +++++++++++++++++--- 4 files changed, 137 insertions(+), 57 deletions(-) diff --git a/blog/asm/1.html b/blog/asm/1.html index d46759f..fcaae55 100644 --- a/blog/asm/1.html +++ b/blog/asm/1.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + x86 Assembly from my understanding @@ -23,9 +23,9 @@

Soooo this article (or maybe even a series of articles, who knows ?) will be about x86 assembly, or rather, what I understood from it and my road from the bottom-up hopefully reaching a good level of understanding

-
-

Memory :

-
+
+

Memory :

+

Memory is a sequence of octets (Aka 8bits) that each have a unique integer assigned to them called The Effective Address (EA), in this particular CPU Architecture (the i8086), the octet is designated by a couple (A segment number, and the offset in the segment)

@@ -40,9 +40,9 @@ Memory is a sequence of octets (Aka 8bits) that each have a unique integer assig The offset and segment are encoded in 16bits, so they take a value between 0 and 65535

-
-

Important :

-
+
+

Important :

+

The relation between the Effective Address and the Segment & Offset is as follow :

@@ -52,10 +52,10 @@ The relation between the Effective Address and the Segment & Offset is as fo

    -
  • Example :
    -
    +
  • Example :
    +

    -Let the Physical address (Or Effective Address, these two terms are enterchangeable) 12345h (the h refers to Hexadecimal, which can also be written like this 0x12345), the register DS = 1230h and the register SI = 0045h, the CPU calculates the physical address by multiplying the content of the segment register DS by 10h (or 16) and adding the content of the register SI. so we get : 1230h x 10h + 45h = 12345h +Let the Physical address (Or Effective Address, these two terms are interchangeable) 12345h (the h refers to Hexadecimal, which can also be written like this 0x12345), the register DS = 1230h and the register SI = 0045h, the CPU calculates the physical address by multiplying the content of the segment register DS by 10h (or 16) and adding the content of the register SI. so we get : 1230h x 10h + 45h = 12345h

    @@ -66,16 +66,16 @@ Now if you are a clever one ( I know you are, since you are reading this <3 )
-
-

Registers

-
+
+

Registers

+

The 8086 CPU has 14 registers of 16bits of size. From the POV of the user, the 8086 has 3 groups of 4 registers of 16bits. One state register of 9bits and a counting program of 16bits inaccessible to the user (whatever this means).

-
-

General Registers

-
+
+

General Registers

+

General registers contribute to arithmetic’s and logic and addressing too.

@@ -126,28 +126,28 @@ Now here are the Registers we can find in this section:
-
-

Addressing and registers…again

-
+
+

Addressing and registers…again

+
-
-

I realized what I wrote here before was almost gibberish, sooo here we go again I guess ?

-
+
+

I realized what I wrote here before was almost gibberish, sooo here we go again I guess ?

+

Well lets take a step back to the notion of effective addresses VS relative ones.

-
-

Effective = 10h x Segment + Offset . Part1

-
+
+

Effective = 10h x Segment + Offset . Part1

+

When trying to access a specific memory space, we use this annotation [Segment:Offset], so for example, and assuming DS = 0100h. We want to write the value 0x0005 to the memory space defined by the physical address 1234h, what do we do ?

    -
  • Answer :
    -
    +
  • Answer :
    +
    MOV [DS:0234h], 0x0005
     
    @@ -159,7 +159,7 @@ Why ? Let’s break it down : -
    +

    lain-dance.gif

    @@ -177,9 +177,9 @@ Simple, right ?, now for another example
-
-

Another example :

-
+
+

Another example :

+

What if we now have this instruction ?

@@ -192,9 +192,9 @@ What does it do ? You might or might not be surprised that it does the exact sam

-
-

Segment + Register <3

-
+
+

Segment + Register <3

+

Consider DS = 0100h and BX = BP = 0234h and this code snippet:

@@ -230,8 +230,8 @@ The General rule of thumb is as follows :
    -
  • Note
    -
    +
  • Note
    +

    The values of the registers CS DS and SS are automatically initialized by the OS when launching the program. So these segments are implicit. AKA : If we want to access a specific data in memory, we just need to specify its offset. Also you can’t write directly into the DS or CS segment registers, so something like

    @@ -249,7 +249,7 @@ The values of the registers CS DS and SS are automatically initialized by the OS

    Author: Crystal

    -

    Created: 2024-03-07 Thu 20:55

    +

    Created: 2024-03-17 Sun 21:28

    diff --git a/blog/c/cherry.html b/blog/c/cherry.html index 9b5da84..e2d9221 100644 --- a/blog/c/cherry.html +++ b/blog/c/cherry.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Reviving Caesar with a Cherry-flavored Crystal @@ -20,17 +20,17 @@ HOME

Reviving Caesar with a Cherry-flavored Crystal

-
-

What ?…

-
+
+

What ?…

+

That is probably your reaction reading this title, and no, this isn’t a randomly generated sentence, but rather a simple encryption algorithm I recently made (Actually the first encryption algorithm i make at all!!). Meet Cherry-Crystal Encryption.

-
-

Okay so, what is this all about ?

-
+
+

Okay so, what is this all about ?

+

This encryption Algorithm that we will call CCE for short, takes inspiration from the Caesar cipher which needn’t an introduction (you can find great explanations online). But what about mine you might ask ?

@@ -44,15 +44,15 @@ This encryption Algorithm that we will call CCE for short, takes inspirat
-
-

The Code :

-
+
+

The Code :

+
#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-void encrypt(char cherry[], char crystal[], int mask[]) {
+void sloth(char cherry[], char crystal[], int mask[]) {
   int i;
   for (i = 0; i < strlen(cherry) - 1; i++) {
     mask[i] = cherry[i] - crystal[i];
@@ -61,7 +61,7 @@ This encryption Algorithm that we will call CCE for short, takes inspirat
     mask[i] = crystal[i];
   }
 }
-void decrypt(char cherry[], char crystal[], int mask[], int length) {
+void moon(char cherry[], char crystal[], int mask[], int length) {
   int i, end = 1;
   for (i = 0; i < length; i++) {
     if (i == strlen(cherry) - 1 || end == 0) {
@@ -81,7 +81,7 @@ This encryption Algorithm that we will call CCE for short, takes inspirat
   fgets(cherry, size, stdin);
   puts("Enter the Crystal: ");
   fgets(crystal, size, stdin);
-  encrypt(cherry, crystal, mask);
+  sloth(cherry, crystal, mask);
   for (i = 0; i < strlen(crystal) - 1; i++) {
     printf("%d ", mask[i]);
     length++;
@@ -97,7 +97,7 @@ This encryption Algorithm that we will call CCE for short, takes inspirat
     scanf("%d", &mask2[i]);
   }
   puts("The Crystal is: ");
-  decrypt(cherry2, crystal2, mask2, length);
+  moon(cherry2, crystal2, mask2, length);
   puts(crystal2);
   return 0;
 }
@@ -110,10 +110,62 @@ The program has been tested both on Alpine OS with Musl libc (thanks 
+

How does it work ?

+
+
+
+

Slothing (Encrypting) 🦥:

+
+

+What is it with these names I pick ? Anyways, the sloth(char *cherry, char *crystal, int *mask) void function takes as parameters three variables: +

+ +
    +
  • A pointer to a char array or simply said a string, It’s the Cherry.
  • +
  • Another pointer to the Crystal.
  • +
  • And Finally, a pointer to an array of integers The Mask which will be output-ed by the function.
  • +
+ + +

+The general idea of it is like this : (we will use a quick example) +

+ +
    +
  • Cherry: H e l l o \0.
  • +
  • Crystal: W o r l d \0.
  • +
  • Cherry[0] here is H, or in ASCII 72. And Crystal[0] is W or 87.
  • +
  • Mask[0] in this case is : Cherry[0] - Crystal[0]. which is -15. We then repeat the same steps for each letter on the Crystal.
  • +
+ +

+Why the emphasis on Crystal ? Because we might end up with a case of a Crystal larger than a Cherry. we set the offset to the ASCII value of Crystal[i], okay which to be fair is not the safest option out there, but I’m planning on fixing it sooner or later. In the case of a large Cherry but a small Crystal…it works but now looking at the code, i have no idea why it works the intended way…. +

+
+
+
+

Mooning (Decrypting) 🌕:

+
+

+The function moon(char *cherry, char *crystal, int *mask, int length) works the same way as the sloth function, but in reverse and a small change. +

+ +
    +
  • The for loop goes through all the elements of the Mask and reconstructing the Crystal using the reverse equation of the encryption. But when it arrives at the end of the Cherry (here we enter the case of a Cherry smaller than a Crystal). Then we will just assume that Mask[i] is the ASCII code of Crystal[i], and we continue this assumption until the end of the loop.
  • +
+ + +

+And voila that’s it. Of course there might be some things I will change, but the overall concept is here! +

+
+
+

Author: Crystal & Sloth

-

Created: 2024-03-16 Sat 21:42

+

Created: 2024-03-17 Sun 21:46

diff --git a/src/org/blog/assembly/1.org b/src/org/blog/assembly/1.org index 0ed897b..e268824 100644 --- a/src/org/blog/assembly/1.org +++ b/src/org/blog/assembly/1.org @@ -29,7 +29,7 @@ The relation between the Effective Address and the Segment & Offset is as follow **Effective address = 16 x segment + offset** keep in mind that this equation is encoded in decimal, which will change soon as we use Hexadecimal for convention reasons. **** Example : -Let the Physical address (Or Effective Address, these two terms are enterchangeable) *12345h* (the h refers to Hexadecimal, which can also be written like this *0x12345*), the register *DS = 1230h* and the register *SI = 0045h*, the CPU calculates the physical address by multiplying the content of the segment register *DS* by 10h (or 16) and adding the content of the register *SI*. so we get : *1230h x 10h + 45h = 12345h* +Let the Physical address (Or Effective Address, these two terms are interchangeable) *12345h* (the h refers to Hexadecimal, which can also be written like this *0x12345*), the register *DS = 1230h* and the register *SI = 0045h*, the CPU calculates the physical address by multiplying the content of the segment register *DS* by 10h (or 16) and adding the content of the register *SI*. so we get : *1230h x 10h + 45h = 12345h* Now if you are a clever one ( I know you are, since you are reading this <3 ) you may say that the physical address *12345h* can be written in more than one way....and you are right, more precisely : *2^{12} = 4096* different ways !!! diff --git a/src/org/blog/c/cherry.org b/src/org/blog/c/cherry.org index 324aa4c..beb7939 100644 --- a/src/org/blog/c/cherry.org +++ b/src/org/blog/c/cherry.org @@ -30,7 +30,7 @@ This encryption Algorithm that we will call *CCE* for short, takes inspiration f #include #include -void encrypt(char cherry[], char crystal[], int mask[]) { +void sloth(char cherry[], char crystal[], int mask[]) { int i; for (i = 0; i < strlen(cherry) - 1; i++) { mask[i] = cherry[i] - crystal[i]; @@ -39,7 +39,7 @@ void encrypt(char cherry[], char crystal[], int mask[]) { mask[i] = crystal[i]; } } -void decrypt(char cherry[], char crystal[], int mask[], int length) { +void moon(char cherry[], char crystal[], int mask[], int length) { int i, end = 1; for (i = 0; i < length; i++) { if (i == strlen(cherry) - 1 || end == 0) { @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) { fgets(cherry, size, stdin); puts("Enter the Crystal: "); fgets(crystal, size, stdin); - encrypt(cherry, crystal, mask); + sloth(cherry, crystal, mask); for (i = 0; i < strlen(crystal) - 1; i++) { printf("%d ", mask[i]); length++; @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) { scanf("%d", &mask2[i]); } puts("The Crystal is: "); - decrypt(cherry2, crystal2, mask2, length); + moon(cherry2, crystal2, mask2, length); puts(crystal2); return 0; } @@ -83,3 +83,31 @@ int main(int argc, char *argv[]) { #+END_SRC The program has been tested both on Alpine OS with Musl libc (thanks [[https://kaa.neocities.org/][Kin]]) and on OpenBSD 7.5-current. In the close future I will make a git repo as i'm planning to upgrade it and just make it better overall, who knows, maybe i will make a library out of it!! + + +* How does it work ? +** Slothing (Encrypting) 🦥: ++What is it with these names I pick ?+ Anyways, the *sloth(char *cherry, char *crystal, int *mask)* void function takes as parameters three variables: + +- A pointer to a *char array* or simply said *a string*, It's the *Cherry*. +- Another pointer to the *Crystal*. +- And Finally, a pointer to an array of integers *The Mask* which will be output-ed by the function. + + +The general idea of it is like this : (we will use a quick example) + +- *Cherry*: H e l l o \0. +- *Crystal*: W o r l d \0. +- Cherry[0] here is *H*, or in ASCII *72*. And Crystal[0] is *W* or *87*. +- Mask[0] in this case is : Cherry[0] - Crystal[0]. which is *-15*. We then repeat the same steps for each letter on the *Crystal*. + +Why the emphasis on *Crystal* ? Because we might end up with a case of a Crystal larger than a Cherry. we set the offset to the ASCII value of *Crystal[i]*, okay which to be fair is not the safest option out there, but I'm planning on fixing it sooner or later. In the case of a large Cherry but a small Crystal...it works but now looking at the code, i have no idea why it works the intended way.... + + +** Mooning (Decrypting) 🌕: +The function *moon(char *cherry, char *crystal, int *mask, int length)* works the same way as the sloth function, but in reverse and a small change. + +- *The for loop goes through all the elements of the Mask and reconstructing the Crystal using the reverse equation of the encryption*. But when it arrives at the end of the *Cherry* (here we enter the case of a Cherry smaller than a Crystal). Then we will just assume that *Mask[i]* is the ASCII code of *Crystal[i]*, and we continue this assumption until the end of the loop. + + +And voila that's it. Of course there might be some things I will change, but the overall concept is here! -- cgit 1.4.1-2-gfad0