summary refs log tree commit diff stats
path: root/src/org/blog/c
diff options
context:
space:
mode:
authorCrystal <crystal@wizard.tower>2024-03-17 21:46:44 +0100
committerCrystal <crystal@wizard.tower>2024-03-17 21:46:44 +0100
commite8c190c8b2984cd562ba65890ad86213a13b9e72 (patch)
treece0b881ede4f9c8b8b49989db4dc404a0acf4850 /src/org/blog/c
parent8347b8d1f799e38d8ce88da706460ccd8aa7f8d3 (diff)
downloadwww-e8c190c8b2984cd562ba65890ad86213a13b9e72.tar.gz
New
Diffstat (limited to 'src/org/blog/c')
-rw-r--r--src/org/blog/c/cherry.org36
1 files changed, 32 insertions, 4 deletions
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 <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];
@@ -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!