- C 86.8%
- Makefile 13.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| cli | ||
| lib | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
SweeCrypt-c
A basic and fun cipher module for everyone. It converts regular text into symbols on a keyboard, kind of like a cipher. This is only for fun, using this module for cybersecurity is NOT ADVISED
This is a port of SweeCrypt-py to C.
This only relies on the standard library, it compiles with musl, so it might as well with glibc.
Currently, I'm still learning C, so this implementation may be a bit unstable, this is the first ever project I made in C.
If you get segfaults from this implementation, PLEASE REPORT A BUG! show your code snippet or CLI call in the issue.
Known to work on
- Linux
- Using gcc, tcc, and clang
- Known to work with glibc and musl
- FreeBSD
- Using gcc and clang
- Haiku
- Using gcc
- Headers are installed separately,
pkgman install haiku_devel - Cannot statically link properly
- Add
WHERE="/Haiku/system/non-packaged"when usingmake install
- Windows
- Via MSYS2 using gcc and clang
- Library and test can compile with MSVC, but CLI won't compile because Windows isn't POSIX and doesn't include
unistd.h
Compiling
Library
$ cd lib
$ make
$ make test # optional
# make install # optional
This compiles both a shared object and static library
CLI
Make sure you compiled the library first
$ cd cli
$ make
# make install # optional
You can also statically link so you don't need to have libsweecrypt.so installed, but you'll probably make some nerds yell at you and/or begin an argument on the IRC channel you shared it on.
$ make LDFLAGS="-lsweecrypt -static"
Or only statically link SweeCrypt
$ make LDFLAGS="-Wl,-Bstatic -lsweecrypt -Wl,-Bdynamic"
Usage
CLI help
$ sweecrypt --help
SweeCrypt-c v1.1.1 - https://git.swee.codes/swee/SweeCrypt-c
An easy and fun encryption module and app
Copyright 2024-2026 Swee
This software is licensed with MIT license
Usage: sweecrypt [encrypt|decrypt] (--shift <n>) <msg>
Commands
encrypt [str] Encodes a message from stdin or parameter
decrypt [str] Decodes a message from stdin or parameter
Flags
--help Shows this message
--shift <int> Specifies a database shift
Notes about C API
Although this C API is more cursed than the other implementations, it's still quite simple to use.
These examples are valid, compilable C programs.
#include <stdio.h>
#include "sweecrypt.h"
int main() {
// Input
char text[] = "hello, world!";
// Buffer
char buf[14]; // Length should be equal to the length of the input including \0
// Sweecrypting
size_t size = sweecrypt_encrypt(text, buf, 14, 0);
// ^ ^ ^ ^
// input | | shift
// result buffer |
// size of result buffer
if (size) {
printf("%s\n", buf);
} else {
printf("Failed to encode\n")
}
return 0;
}
Tip
Although the functions return the final buffer's size, you can just call the function without defining a variable for it, but it's usually a good idea to use the returned value for error handling
SweeCrypt will return 0 if either no characters are in db, or the buffer size is less than the input length (including\0)
Make sure to include -lsweecrypt when compiling.
Encode
#include <stdio.h>
#include "sweecrypt.h"
int main() {
char text[] = "hello, world!";
char buf[14];
sweecrypt_encrypt(text, buf, 14, 0);
printf("%s\n", buf);
return 0;
}
$ sweecrypt encrypt "hello, world!"
!?~~(:,}(>~/a
Decode
#include <stdio.h>
#include "sweecrypt.h"
int main() {
char text[] = "!?~~(:,}(>~/a";
char buf[14];
sweecrypt_decrypt(text, buf, 14, 0);
printf("%s\n", buf);
return 0;
}
$ sweecrypt decrypt '!?~~(:,}(>~/a'
hello, world!
Shifting DB
#include <stdio.h>
#include "sweecrypt.h"
int main() {
// Encode
char text[] = "hello, world!";
char enc[14];
sweecrypt_encrypt(text, enc, 14, 3);
printf("%s\n", enc);
// Correct output (dec_correct will match text)
char dec_correct[14];
sweecrypt_decrypt(enc, dec_correct, 14, 3);
printf("%s\n", dec_correct);
// Incorrect output (Nonsense string)
char dec_wrong[14];
sweecrypt_decrypt(enc, dec_wrong, 14, 0);
printf("%s\n", dec_wrong);
return 0;
}
$ sweecrypt encrypt --shift 3 "hello, world"
\!((>ba_>](#
$ sweecrypt decrypt --shift 3 "\!((>ba_>](#"
hello, world
$ sweecrypt decrypt "\!((>ba_>](#"
khoor?!zruog