From 5fc3091bcce01ab4000d0afd7c65ec303fe99c89 Mon Sep 17 00:00:00 2001 From: Crystal Date: Sat, 16 Mar 2024 21:42:29 +0100 Subject: New --- src/org/blog/c/cherry.org | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/org/blog/c/cherry.org (limited to 'src/org') 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: +#+HTML_HEAD: +#+OPTIONS: html-style:nil +#+OPTIONS: toc:nil +#+HTML_HEAD: +#+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 +#include +#include + +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!! -- cgit 1.4.1-2-gfad0