Skip to content

Instantly share code, notes, and snippets.

Question 2: Steganography using 4-bit LSB algorithm
Scope: File Processing, Pointers, Dynamic Memory Allocation (No arrays)
File to use: stego_lsb.c
Preliminary:
This question should be solved using dynamic memory allocation along with
pointers. Any submitted work which includes an array will be given
automatically a zero mark. To view pgm files, you can use the “Irfan View”
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t))
#define S(s) (Str){(uint8_t *)s, sizeof(s)-1}
@skeeto
skeeto / demo.cpp
Created October 3, 2024 22:27
Slim Reader/Writer Condition Variable Demo / Test
// Slim Reader/Writer Condition Variable Demo / Test
// $ cc -nostartfiles -o main.exe demo.cpp
// $ cl /GS- demo.cpp /link /subsystem:console kernel32.lib
// This is free and unencumbered software released into the public domain.
#define assert(c) while (!(c)) *(volatile i32 *)-4 = 0
using b32 = signed;
using i32 = signed;
using uz = decltype(sizeof(0));
@skeeto
skeeto / testenv.cpp
Created September 30, 2024 23:22
Quick test of environment variable passing
// Quick test of environment variable passing
// $ cc -nostartfiles -o testenv testenv.cpp
// $ cl testenv.cpp /link /subsystem:console kernel32.lib
//
// Spawns a copy of itself with a custom-built environment block, and
// the spawned child examines/probes that block.
//
// This is free and unencumbered software released into the public domain.
typedef int I;
// Ref: https://old.reddit.com/r/C_Programming/comments/1e30ce8/
#include <stddef.h>
#include <stdio.h>
#define S(s) (str){s, sizeof(s)-1}
typedef struct {
char *data;
ptrdiff_t len;
} str;
@skeeto
skeeto / quilt.c
Last active June 25, 2024 01:30
Quilt layout solver
// Quilt layout solver (example)
// $ cc -o quilt quilt.c
// Ref: https://old.reddit.com/r/algorithms/comments/1dn97c0
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define countof(a) (ptrdiff_t)(sizeof(a) / sizeof(*(a)))
@skeeto
skeeto / main.c
Last active October 7, 2024 00:49
// Ref: https://old.reddit.com/r/C_Programming/comments/1dlc4kw
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define new(n, t) (t *)calloc(n, sizeof(t))
typedef struct node node;
struct node {
@skeeto
skeeto / squares.c
Created June 12, 2024 13:38
Flawless Squares
// Flawless Squares
// $ cc -fopenmp -O2 -o squares squares.c
// Ref: https://old.reddit.com/r/C_Programming/comments/1de40e0
// This is free and unencumbered software released into the public domain.
#include <stdio.h>
int main(void)
{
#pragma omp parallel for schedule(dynamic, 100000)
for (long long root = 1; root < 3037000500; root++) {
@skeeto
skeeto / kanzi.cpp
Last active May 31, 2024 15:50
Kanzi unity build
// $ c++ -o kanzi kanzi.cpp
#define WIN32_LEAN_AND_MEAN // avoids std::byte conflicts
#include "src/app/BlockDecompressor.cpp"
#include "src/app/Kanzi.cpp"
#include "src/app/InfoPrinter.cpp"
#include "src/app/BlockCompressor.cpp"
#include "src/transform/BWTS.cpp"
#include "src/transform/BWTBlockCodec.cpp"
#include "src/transform/SBRT.cpp"
#include "src/transform/ZRLT.cpp"
@skeeto
skeeto / arena-commit.c
Created May 25, 2024 00:43
Growing arena persisting commit level through scratch copies
#define assert(c) while (!(c)) __builtin_unreachable()
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t))
enum { PAGESIZE = 1<<12 };
typedef signed int b32;
typedef signed int i32;
typedef char byte;
typedef signed long long iz;
typedef unsigned long long uz;