summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--blog/c/cherry.html119
-rw-r--r--src/org/blog/c/cherry.org85
2 files changed, 204 insertions, 0 deletions
diff --git a/blog/c/cherry.html b/blog/c/cherry.html
new file mode 100644
index 0000000..9b5da84
--- /dev/null
+++ b/blog/c/cherry.html
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head>
+<!-- 2024-03-16 Sat 21:42 -->
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+<meta name="viewport" content="width=device-width, initial-scale=1" />
+<title>Reviving Caesar with a Cherry-flavored Crystal</title>
+<meta name="author" content="Crystal &amp; Sloth" />
+<meta name="generator" content="Org Mode" />
+<link rel="stylesheet" type="text/css" href="../../src/css/colors.css"/>
+<link rel="stylesheet" type="text/css" href="../../src/css/style.css"/>
+<link rel="icon" type="image/x-icon" href="../../../favicon.png">
+</head>
+<body>
+<div id="org-div-home-and-up">
+ <a accesskey="h" href=""> UP </a>
+ |
+ <a accesskey="H" href="https://crystal.tilde.institute/"> HOME </a>
+</div><div id="content" class="content">
+<h1 class="title">Reviving Caesar with a Cherry-flavored Crystal</h1>
+<div id="outline-container-org394c654" class="outline-2">
+<h2 id="org394c654">What ?&#x2026;</h2>
+<div class="outline-text-2" id="text-org394c654">
+<p>
+That is probably your reaction reading this title, and no, this isn&rsquo;t a randomly generated sentence, but rather a simple encryption algorithm I recently made (Actually the first encryption algorithm i make at all!!). Meet <b>Cherry-Crystal Encryption</b>.
+</p>
+</div>
+</div>
+<div id="outline-container-org5a46ff7" class="outline-2">
+<h2 id="org5a46ff7">Okay so, what is this all about ?</h2>
+<div class="outline-text-2" id="text-org5a46ff7">
+<p>
+This encryption Algorithm that we will call <b>CCE</b> for short, takes inspiration from the Caesar cipher which needn&rsquo;t an introduction (you can find great explanations online). But what about mine you might ask ?
+</p>
+
+
+<ul class="org-ul">
+<li>It&rsquo;s actually pretty simple. We start with a <b>Cherry</b> or a <b>Visible phrase</b>, or a <b>Decoy</b>, that we will share to people who we don&rsquo;t want to know the secret phrase..</li>
+<li>Then we ask the user to enter their <b>Crystal</b>, <b>invisible phrase</b> or <b>secret</b>.</li>
+<li>The program then outputs an array of Integers called the <b>Mask</b>, or the <b>Shift</b>. That is, the shift required to go from cherry<sub>i</sub> to crystal<sub>i</sub>.</li>
+<li>Finally, we use both the <b>Cherry</b> and <b>Mask</b> to get the <b>Crystal</b>, a single missing number or letter from both of them can and will output rubbish content.</li>
+</ul>
+</div>
+</div>
+<div id="outline-container-org9e305ea" class="outline-2">
+<h2 id="org9e305ea">The Code :</h2>
+<div class="outline-text-2" id="text-org9e305ea">
+<div class="org-src-container">
+<pre class="src src-c"><span style="color: #f9e2af;">#include</span> <span style="color: #f38ba8;">&lt;</span><span style="color: #a6e3a1;">stdio.h</span><span style="color: #f38ba8;">&gt;</span>
+<span style="color: #f9e2af;">#include</span> <span style="color: #f38ba8;">&lt;</span><span style="color: #a6e3a1;">stdlib.h</span><span style="color: #f38ba8;">&gt;</span>
+<span style="color: #f9e2af;">#include</span> <span style="color: #f38ba8;">&lt;</span><span style="color: #a6e3a1;">string.h</span><span style="color: #f38ba8;">&gt;</span>
+
+<span style="color: #f9e2af;">void</span> <span style="color: #89b4fa;">encrypt</span><span style="color: #f38ba8;">(</span><span style="color: #f9e2af;">char</span> <span style="color: #cdd6f4;">cherry</span><span style="color: #fab387;">[]</span>, <span style="color: #f9e2af;">char</span> <span style="color: #cdd6f4;">crystal</span><span style="color: #fab387;">[]</span>, <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">mask</span><span style="color: #fab387;">[]</span><span style="color: #f38ba8;">)</span> <span style="color: #f38ba8;">{</span>
+  <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">i</span>;
+  <span style="color: #cba6f7;">for</span> <span style="color: #fab387;">(</span>i = <span style="color: #fab387;">0</span>; i &lt; strlen<span style="color: #f9e2af;">(</span>cherry<span style="color: #f9e2af;">)</span> - <span style="color: #fab387;">1</span>; i++<span style="color: #fab387;">)</span> <span style="color: #fab387;">{</span>
+    mask<span style="color: #f9e2af;">[</span>i<span style="color: #f9e2af;">]</span> = cherry<span style="color: #f9e2af;">[</span>i<span style="color: #f9e2af;">]</span> - crystal<span style="color: #f9e2af;">[</span>i<span style="color: #f9e2af;">]</span>;
+  <span style="color: #fab387;">}</span>
+  <span style="color: #cba6f7;">for</span> <span style="color: #fab387;">(</span>i = strlen<span style="color: #f9e2af;">(</span>cherry<span style="color: #f9e2af;">)</span> - <span style="color: #fab387;">1</span>; i &lt; strlen<span style="color: #f9e2af;">(</span>crystal<span style="color: #f9e2af;">)</span> - <span style="color: #fab387;">1</span>; i++<span style="color: #fab387;">)</span> <span style="color: #fab387;">{</span>
+    mask<span style="color: #f9e2af;">[</span>i<span style="color: #f9e2af;">]</span> = crystal<span style="color: #f9e2af;">[</span>i<span style="color: #f9e2af;">]</span>;
+  <span style="color: #fab387;">}</span>
+<span style="color: #f38ba8;">}</span>
+<span style="color: #f9e2af;">void</span> <span style="color: #89b4fa;">decrypt</span><span style="color: #f38ba8;">(</span><span style="color: #f9e2af;">char</span> <span style="color: #cdd6f4;">cherry</span><span style="color: #fab387;">[]</span>, <span style="color: #f9e2af;">char</span> <span style="color: #cdd6f4;">crystal</span><span style="color: #fab387;">[]</span>, <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">mask</span><span style="color: #fab387;">[]</span>, <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">length</span><span style="color: #f38ba8;">)</span> <span style="color: #f38ba8;">{</span>
+  <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">i</span>, <span style="color: #cdd6f4;">end</span> = <span style="color: #fab387;">1</span>;
+  <span style="color: #cba6f7;">for</span> <span style="color: #fab387;">(</span>i = <span style="color: #fab387;">0</span>; i &lt; length; i++<span style="color: #fab387;">)</span> <span style="color: #fab387;">{</span>
+    <span style="color: #cba6f7;">if</span> <span style="color: #f9e2af;">(</span>i == strlen<span style="color: #a6e3a1;">(</span>cherry<span style="color: #a6e3a1;">)</span> - <span style="color: #fab387;">1</span> || end == <span style="color: #fab387;">0</span><span style="color: #f9e2af;">)</span> <span style="color: #f9e2af;">{</span>
+      crystal<span style="color: #a6e3a1;">[</span>i<span style="color: #a6e3a1;">]</span> = mask<span style="color: #a6e3a1;">[</span>i<span style="color: #a6e3a1;">]</span>;
+      end = <span style="color: #fab387;">0</span>;
+    <span style="color: #f9e2af;">}</span> <span style="color: #cba6f7;">else</span> <span style="color: #f9e2af;">{</span>
+      crystal<span style="color: #a6e3a1;">[</span>i<span style="color: #a6e3a1;">]</span> = cherry<span style="color: #a6e3a1;">[</span>i<span style="color: #a6e3a1;">]</span> - mask<span style="color: #a6e3a1;">[</span>i<span style="color: #a6e3a1;">]</span>;
+    <span style="color: #f9e2af;">}</span>
+  <span style="color: #fab387;">}</span>
+<span style="color: #f38ba8;">}</span>
+<span style="color: #f9e2af;">int</span> <span style="color: #89b4fa;">main</span><span style="color: #f38ba8;">(</span><span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">argc</span>, <span style="color: #f9e2af;">char</span> *<span style="color: #cdd6f4;">argv</span><span style="color: #fab387;">[]</span><span style="color: #f38ba8;">)</span> <span style="color: #f38ba8;">{</span>
+  <span style="color: #cba6f7;">const</span> <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">size</span> = <span style="color: #fab387;">1028</span>;
+  <span style="color: #f9e2af;">char</span> <span style="color: #cdd6f4;">cherry</span><span style="color: #fab387;">[</span>size<span style="color: #fab387;">]</span>, <span style="color: #cdd6f4;">cherry2</span><span style="color: #fab387;">[</span>size<span style="color: #fab387;">]</span>, <span style="color: #cdd6f4;">crystal</span><span style="color: #fab387;">[</span>size<span style="color: #fab387;">]</span>, <span style="color: #cdd6f4;">crystal2</span><span style="color: #fab387;">[</span>size<span style="color: #fab387;">]</span>;
+  <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">mask</span><span style="color: #fab387;">[</span>size<span style="color: #fab387;">]</span>, <span style="color: #cdd6f4;">mask2</span><span style="color: #fab387;">[</span>size<span style="color: #fab387;">]</span>, <span style="color: #cdd6f4;">i</span>;
+  <span style="color: #f9e2af;">int</span> <span style="color: #cdd6f4;">length</span> = <span style="color: #fab387;">0</span>;
+  puts<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"Enter the Cherry: "</span><span style="color: #fab387;">)</span>;
+  fgets<span style="color: #fab387;">(</span>cherry, size, stdin<span style="color: #fab387;">)</span>;
+  puts<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"Enter the Crystal: "</span><span style="color: #fab387;">)</span>;
+  fgets<span style="color: #fab387;">(</span>crystal, size, stdin<span style="color: #fab387;">)</span>;
+  encrypt<span style="color: #fab387;">(</span>cherry, crystal, mask<span style="color: #fab387;">)</span>;
+  <span style="color: #cba6f7;">for</span> <span style="color: #fab387;">(</span>i = <span style="color: #fab387;">0</span>; i &lt; strlen<span style="color: #f9e2af;">(</span>crystal<span style="color: #f9e2af;">)</span> - <span style="color: #fab387;">1</span>; i++<span style="color: #fab387;">)</span> <span style="color: #fab387;">{</span>
+    printf<span style="color: #f9e2af;">(</span><span style="color: #a6e3a1;">"%d "</span>, mask<span style="color: #a6e3a1;">[</span>i<span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span>;
+    length++;
+  <span style="color: #fab387;">}</span>
+  printf<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"\nYour mask is : %d characters long"</span>, length<span style="color: #fab387;">)</span>;
+  puts<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"\n===Decryption: ===\n"</span><span style="color: #fab387;">)</span>;
+  puts<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"Enter the Cherry: "</span><span style="color: #fab387;">)</span>;
+  fgets<span style="color: #fab387;">(</span>cherry2, size, stdin<span style="color: #fab387;">)</span>;
+  puts<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"Enter the size of the Mask: "</span><span style="color: #fab387;">)</span>;
+  scanf<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"%d"</span>, &amp;length<span style="color: #fab387;">)</span>;
+  puts<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"Enter the mask: "</span><span style="color: #fab387;">)</span>;
+  <span style="color: #cba6f7;">for</span> <span style="color: #fab387;">(</span>i = <span style="color: #fab387;">0</span>; i &lt; length; i++<span style="color: #fab387;">)</span> <span style="color: #fab387;">{</span>
+    scanf<span style="color: #f9e2af;">(</span><span style="color: #a6e3a1;">"%d"</span>, &amp;mask2<span style="color: #a6e3a1;">[</span>i<span style="color: #a6e3a1;">]</span><span style="color: #f9e2af;">)</span>;
+  <span style="color: #fab387;">}</span>
+  puts<span style="color: #fab387;">(</span><span style="color: #a6e3a1;">"The Crystal is: "</span><span style="color: #fab387;">)</span>;
+  decrypt<span style="color: #fab387;">(</span>cherry2, crystal2, mask2, length<span style="color: #fab387;">)</span>;
+  puts<span style="color: #fab387;">(</span>crystal2<span style="color: #fab387;">)</span>;
+  <span style="color: #cba6f7;">return</span> <span style="color: #fab387;">0</span>;
+<span style="color: #f38ba8;">}</span>
+
+</pre>
+</div>
+
+<p>
+The program has been tested both on Alpine OS with Musl libc (thanks <a href="https://kaa.neocities.org/">Kin</a>) and on OpenBSD 7.5-current. In the close future I will make a git repo as i&rsquo;m planning to upgrade it and just make it better overall, who knows, maybe i will make a library out of it!!
+</p>
+</div>
+</div>
+</div>
+<div id="postamble" class="status">
+<p class="author">Author: Crystal &amp; Sloth</p>
+<p class="date">Created: 2024-03-16 Sat 21:42</p>
+</div>
+</body>
+</html>
diff --git a/src/org/blog/c/cherry.org b/src/org/blog/c/cherry.org
new file mode 100644
index 0000000..324aa4c
--- /dev/null
+++ b/src/org/blog/c/cherry.org
@@ -0,0 +1,85 @@
+#+title: Reviving Caesar with a Cherry-flavored Crystal
+#+AUTHOR: Crystal & Sloth
+#+OPTIONS: ^:{}
+#+OPTIONS: num:nil
+#+EXPORT_FILE_NAME: ../../../../blog/c/cherry.html
+#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../src/css/colors.css"/>
+#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../src/css/style.css"/>
+#+OPTIONS: html-style:nil
+#+OPTIONS: toc:nil
+#+HTML_HEAD: <link rel="icon" type="image/x-icon" href="../../../favicon.png">
+#+HTML_LINK_HOME: https://crystal.tilde.institute/
+
+* 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 ?
+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 ?
+
+
+- It's actually pretty simple. We start with a *Cherry* or a *Visible phrase*, or a *Decoy*, that we will share to people who we don't want to know the secret phrase..
+- Then we ask the user to enter their *Crystal*, *invisible phrase* or *secret*.
+- The program then outputs an array of Integers called the *Mask*, or the *Shift*. That is, the shift required to go from cherry_{i} to crystal_{i}.
+- Finally, we use both the *Cherry* and *Mask* to get the *Crystal*, a single missing number or letter from both of them can and will output rubbish content.
+
+
+* The Code :
+ #+BEGIN_SRC c
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void encrypt(char cherry[], char crystal[], int mask[]) {
+  int i;
+  for (i = 0; i < strlen(cherry) - 1; i++) {
+    mask[i] = cherry[i] - crystal[i];
+  }
+  for (i = strlen(cherry) - 1; i < strlen(crystal) - 1; i++) {
+    mask[i] = crystal[i];
+  }
+}
+void decrypt(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) {
+      crystal[i] = mask[i];
+      end = 0;
+    } else {
+      crystal[i] = cherry[i] - mask[i];
+    }
+  }
+}
+int main(int argc, char *argv[]) {
+  const int size = 1028;
+  char cherry[size], cherry2[size], crystal[size], crystal2[size];
+  int mask[size], mask2[size], i;
+  int length = 0;
+  puts("Enter the Cherry: ");
+  fgets(cherry, size, stdin);
+  puts("Enter the Crystal: ");
+  fgets(crystal, size, stdin);
+  encrypt(cherry, crystal, mask);
+  for (i = 0; i < strlen(crystal) - 1; i++) {
+    printf("%d ", mask[i]);
+    length++;
+  }
+  printf("\nYour mask is : %d characters long", length);
+  puts("\n===Decryption: ===\n");
+  puts("Enter the Cherry: ");
+  fgets(cherry2, size, stdin);
+  puts("Enter the size of the Mask: ");
+  scanf("%d", &length);
+  puts("Enter the mask: ");
+  for (i = 0; i < length; i++) {
+    scanf("%d", &mask2[i]);
+  }
+  puts("The Crystal is: ");
+  decrypt(cherry2, crystal2, mask2, length);
+  puts(crystal2);
+  return 0;
+}
+
+ #+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!!