row_id,chapter,section,content,code_sample,ascii_value 1,History,Ancient Ciphers,"The Caesar cipher was used by Julius Caesar to communicate with his generals.","shift = 3;",67 2,History,Ancient Ciphers,"The Atbash cipher reversed the alphabet: A becomes Z, B becomes Y.","encrypted = 'Z' - (c - 'A');",65 3,History,Medieval Cryptography,"The Vigenere cipher was considered unbreakable for 300 years.","key[] = ""LEMON"";",76 4,History,Medieval Cryptography,"Frequency analysis was developed by Arab mathematician Al-Kindi.","count[c - 'A']++;",75 5,History,Modern Era,"The Enigma machine used rotors for polyalphabetic substitution.","rotor_position++;",69 6,History,Modern Era,"Alan Turing's work at Bletchley Park helped crack Enigma.","decrypt(ciphertext);",84 7,History,Digital Age,"DES was adopted as a federal standard in 1976.","des_encrypt(block, key);",68 8,History,Digital Age,"AES replaced DES in 2001 with 128/192/256-bit keys.","aes_encrypt(data, key, 256);",65 9,XOR Cipher,Theory,"XOR (exclusive or) is a bitwise operation fundamental to cryptography.","result = a ^ b;",94 10,XOR Cipher,Theory,"XOR truth table: 0^0=0, 0^1=1, 1^0=1, 1^1=0","if((a^b)==1) {...}",94 11,XOR Cipher,Implementation,"Each byte of plaintext is XORed with corresponding key byte.","encrypted[i] = plain[i] ^ key[i % keylen];",94 12,XOR Cipher,Implementation,"The same operation decrypts: ciphertext XOR key = plaintext.","decrypted[i] = cipher[i] ^ key[i % keylen];",94 13,XOR Cipher,Key Handling,"Keys shorter than plaintext are repeated cyclically.","key_index = i % strlen(key);",94 14,XOR Cipher,Key Handling,"Longer keys provide better security against frequency analysis.","use key length >= plaintext length",94 15,XOR Cipher,Weaknesses,"Repeating key XOR is vulnerable to known-plaintext attacks.","if(plain_known) key = plain ^ cipher;",94 16,XOR Cipher,Weaknesses,"One-time pad (key as long as message) is theoretically unbreakable.","key_length == message_length",94 17,Caesar Cipher,Theory,"Each letter is shifted by a fixed amount in the alphabet.","E(x) = (x + n) mod 26",67 18,Caesar Cipher,Theory,"ROT13 is a special case with shift of 13.","ROT13(ROT13(x)) = x",82 19,Caesar Cipher,Implementation,"Only alphabetic characters should be shifted.","if(isalpha(c)) {...}",67 20,Caesar Cipher,Implementation,"Preserve case: uppercase stays uppercase.","if(isupper(c)) base = 'A';",67 21,Caesar Cipher,Implementation,"Non-alphabetic characters pass through unchanged.","else putchar(c);",67 22,Caesar Cipher,Modular Arithmetic,"Use modulo 26 for alphabet wrapping.","result = (c - base + shift) % 26 + base;",37 23,Caesar Cipher,Modular Arithmetic,"Handle negative shifts for decryption.","shift = (26 - shift) % 26;",37 24,Caesar Cipher,Decryption,"Decrypt by shifting in opposite direction.","D(x) = (x - n + 26) mod 26",68 25,Vigenere,Theory,"Polyalphabetic cipher using a keyword.","keyword = ""SECRET"";",86 26,Vigenere,Theory,"Each letter of keyword defines shift for corresponding plaintext letter.","shift = key[i] - 'A';",86 27,Vigenere,Implementation,"Cycle through keyword letters.","key_pos = (key_pos + 1) % keylen;",86 28,Vigenere,Implementation,"Combine Caesar shifts based on keyword.","encrypted = caesar(plain[i], key[key_pos]);",86 29,Vigenere,Advantages,"Resists simple frequency analysis.","multiple substitution alphabets",86 30,Vigenere,Weaknesses,"Vulnerable to Kasiski examination if key repeats.","find_key_length(cipher);",86 31,File I/O,Opening Files,"Use fopen with appropriate mode.","FILE *fp = fopen(filename, ""rb"");",70 32,File I/O,Opening Files,"Always check if file opened successfully.","if(fp == NULL) { perror(""Error""); }",70 33,File I/O,Binary Mode,"Use rb/wb for binary, r/w for text.","FILE *out = fopen(""output.enc"", ""wb"");",98 34,File I/O,Binary Mode,"Text mode may translate newlines on Windows.","\\r\\n vs \\n translation",98 35,File I/O,Reading Data,"fread returns number of items successfully read.","size_t n = fread(buf, 1, SIZE, fp);",102 36,File I/O,Reading Data,"Check for EOF with feof().","while(!feof(fp)) { ... }",102 37,File I/O,Writing Data,"fwrite returns number of items written.","fwrite(buf, 1, n, out);",119 38,File I/O,Writing Data,"Flush buffers with fflush for immediate write.","fflush(out);",119 39,File I/O,Closing Files,"Always close files when done.","fclose(fp);",99 40,File I/O,Closing Files,"Check return value of fclose for errors.","if(fclose(fp) != 0) {...}",99 41,CLI,argc and argv,"argc is count, argv is array of strings.","int main(int argc, char *argv[])",97 42,CLI,argc and argv,"argv[0] is program name.","printf(""Usage: %s [options]\\n"", argv[0]);",97 43,CLI,Parsing Options,"Loop through arguments from index 1.","for(int i=1; i",103 46,CLI,getopt,"Colon after letter means option takes argument.","getopt(argc, argv, ""k:i:o:dh"")",103 47,CLI,Long Options,"getopt_long supports --help style options.","struct option long_opts[] = {...};",103 48,CLI,Help Message,"Provide clear usage instructions.","printf(""Usage: encrypt -a ALG -k KEY -i IN -o OUT\\n"");",104 49,CLI,Error Messages,"Clear errors for invalid input.","fprintf(stderr, ""Error: unknown algorithm\\n"");",101 50,CLI,Exit Codes,"Return 0 for success, non-zero for errors.","return EXIT_FAILURE;",101 51,ASCII,Basic Table,"ASCII values 0-31 are control characters.","\\n = 10, \\t = 9, \\r = 13",0 52,ASCII,Basic Table,"Space is ASCII 32.","' ' == 32",32 53,ASCII,Printable,"Values 32-126 are printable characters.","isprint(c) checks this",33 54,ASCII,Digits,"0-9 are ASCII 48-57.","'0' = 48, '9' = 57",48 55,ASCII,Uppercase,"A-Z are ASCII 65-90.","'A' = 65, 'Z' = 90",65 56,ASCII,Lowercase,"a-z are ASCII 97-122.","'a' = 97, 'z' = 122",97 57,ASCII,Conversion,"toupper and tolower convert case.","c = toupper(c);",116 58,ASCII,Conversion,"Lowercase = uppercase + 32.","lower = upper + 32;",32 59,Test Patterns,Alphabet Upper,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","26 uppercase letters",65 60,Test Patterns,Alphabet Lower,"abcdefghijklmnopqrstuvwxyz","26 lowercase letters",97 61,Test Patterns,Digits,"0123456789","10 digit characters",48 62,Test Patterns,Punctuation,"!@#$%^&*()_+-=[]{}|;:,.<>?","Common punctuation marks",33 63,Test Patterns,Whitespace,"Space, tab, newline, carriage return","\\s matches these in regex",32 64,Test Patterns,Mixed,"The Quick Brown Fox Jumps Over The Lazy Dog 123!","All character types combined",84 65,Memory,Allocation,"Use malloc for dynamic memory.","char *buf = malloc(size);",109 66,Memory,Allocation,"Always check malloc return value.","if(buf == NULL) exit(1);",109 67,Memory,Deallocation,"Free memory when done.","free(buf);",102 68,Memory,Deallocation,"Set pointer to NULL after freeing.","buf = NULL;",102 69,Memory,Buffer Size,"Choose appropriate buffer sizes.","#define BUFFER_SIZE 4096",66 70,Memory,Buffer Size,"Larger buffers = fewer I/O operations.","Trade memory for speed",66 71,Memory,Security,"Clear sensitive data after use.","memset(key, 0, keylen);",109 72,Memory,Security,"Avoid buffer overflows.","strncpy instead of strcpy",109 73,Errors,File Not Found,"Handle missing input files gracefully.","if(access(file, F_OK) != 0) {...}",70 74,Errors,File Not Found,"Provide helpful error messages.","fprintf(stderr, ""File '%s' not found\\n"", file);",70 75,Errors,Permission Denied,"Check file permissions before operations.","if(access(file, R_OK) != 0) {...}",80 76,Errors,Permission Denied,"Handle write permission errors.","if(access(dir, W_OK) != 0) {...}",80 77,Errors,Invalid Arguments,"Validate all user input.","if(shift < 1 || shift > 25) {...}",73 78,Errors,Invalid Arguments,"Show usage on invalid arguments.","print_usage(); exit(1);",73 79,Errors,Memory Errors,"Handle allocation failures.","if(malloc(...) == NULL) {...}",77 80,Errors,Memory Errors,"Use tools like valgrind for debugging.","valgrind ./encrypt ...",77 81,Best Practices,Modularity,"Separate concerns into functions.","void xor_encrypt(char *data, char *key);",77 82,Best Practices,Modularity,"Use header files for declarations.","#include ""encryption.h""",77 83,Best Practices,Comments,"Document function purposes.","/* Encrypts data using XOR cipher */",47 84,Best Practices,Comments,"Explain complex logic inline.","// Handle alphabet wrapping",47 85,Best Practices,Constants,"Use #define for magic numbers.","#define MAX_KEY_LENGTH 256",35 86,Best Practices,Constants,"const for compile-time constants.","const int BUFFER_SIZE = 4096;",99 87,Best Practices,Error Codes,"Use meaningful return values.","enum { SUCCESS=0, ERR_FILE=1, ERR_KEY=2 };",101 88,Best Practices,Error Codes,"Document exit codes in help.","Exit codes: 0=success, 1=file error",101 89,Security,Key Length,"Longer keys are more secure.","Minimum 16 characters recommended",75 90,Security,Key Length,"One-time pad requires key = message length.","Perfect secrecy if truly random",75 91,Security,Randomness,"Use cryptographically secure random for production.","rand() is NOT secure",114 92,Security,Randomness,"Read from /dev/urandom on Unix.","FILE *rnd = fopen(""/dev/urandom"", ""rb"");",114 93,Security,Memory Clearing,"Zero out keys after use.","explicit_bzero(key, keylen);",109 94,Security,Memory Clearing,"Compiler may optimize out memset.","Use volatile or explicit_bzero",109 95,Security,Limitations,"XOR and Caesar are NOT secure for real use.","Educational purposes only!",88 96,Security,Limitations,"Use AES-256 or ChaCha20 for real encryption.","#include ",88 97,Makefile,Basic Structure,"Define compiler and flags.","CC = gcc\\nCFLAGS = -Wall -Wextra",67 98,Makefile,Basic Structure,"Define target and dependencies.","encrypt: src/main.c\\n\\t$(CC) $(CFLAGS) -o $@ $^",67 99,Makefile,Phony Targets,"Declare non-file targets.",".",80 100,Makefile,Phony Targets,"clean removes build artifacts.","\trm -f encrypt *.o",114 101,History,Scytale,"Ancient Greek cipher using a wooden rod.","Wrap strip of leather around rod",83 102,History,Substitution,"Replace each letter with another.","create substitution table",83 103,History,Transposition,"Rearrange letters without changing them.","rail fence cipher",84 104,History,Enigma Details,"3-4 rotors with 26 positions each.","26^3 = 17576 starting positions",69 105,History,Purple,"Japanese diplomatic cipher broken by US.","Similar to Enigma",80 106,XOR Cipher,Streaming,"Process file in chunks for large files.","while(fread(buf, 1, 4096, in) > 0)",94 107,XOR Cipher,Streaming,"Maintain key position across chunks.","static int key_pos = 0;",94 108,XOR Cipher,Key File,"Read key from file for convenience.","FILE *kf = fopen(keyfile, ""r"");",94 109,XOR Cipher,Key File,"Trim newlines from key input.","key[strcspn(key, ""\\n"")] = 0;",94 110,Caesar Cipher,Brute Force,"Only 25 possible keys to try.","for(shift=1; shift<=25; shift++)",67 111,Caesar Cipher,Frequency,"E is most common letter in English.","if(freq['E'-'A'] is highest) shift = ...",67 112,Vigenere,Kasiski,"Find repeated sequences to guess key length.","locate_repeats(cipher);",86 113,Vigenere,Index of Coincidence,"Statistical measure for key length.","IC = sum(f*(f-1)) / (N*(N-1))",86 114,File I/O,fseek,"Move file position indicator.","fseek(fp, 0, SEEK_END);",102 115,File I/O,ftell,"Get current file position.","long size = ftell(fp);",102 116,File I/O,rewind,"Return to beginning of file.","rewind(fp);",114 117,File I/O,tmpfile,"Create temporary file.","FILE *tmp = tmpfile();",116 118,CLI,Environment,"Read environment variables.","char *key = getenv(""ENCRYPT_KEY"");",103 119,CLI,Environment,"Set defaults from environment.","if(key == NULL) key = DEFAULT_KEY;",103 120,ASCII,Extended,"Values 128-255 are extended ASCII.","May vary by codepage",128 121,ASCII,UTF-8,"Multi-byte encoding for Unicode.","Up to 4 bytes per character",239 122,Test Patterns,Repeated,"AAAAAAAAAA","Single character repeated",65 123,Test Patterns,Alternating,"ABABABABAB","Two characters alternating",65 124,Test Patterns,Sequential,"ABCDEFGHIJ","Sequential letters",65 125,Test Patterns,Random,"xK9#mP2@wL","Pseudorandom mix",120 126,Memory,Stack vs Heap,"Local arrays on stack, malloc on heap.","char local[100]; // stack",115 127,Memory,Stack Overflow,"Large arrays may overflow stack.","Use malloc for big buffers",115 128,Errors,Disk Full,"Handle write failures.","if(fwrite(...) < expected) {...}",68 129,Errors,Corrupted Input,"Validate input file format.","check file signature or magic bytes",67 130,Best Practices,Testing,"Test with various file sizes.","small, medium, large, huge",116 131,Best Practices,Edge Cases,"Handle empty files.","if(file_size == 0) {...}",101 132,Security,Side Channels,"Timing attacks can leak information.","Use constant-time operations",116 133,Security,Key Derivation,"Derive keys from passwords with PBKDF2.","#include ",107 134,Makefile,Variables,"Use variables for flexibility.","SRC = $(wildcard src/*.c)",86 135,Makefile,Pattern Rules,"Generic rules for file types.","%.o: %.c\\n\\t$(CC) -c $<",37 136,History,RSA,"First widely used asymmetric cipher (1977).","Public key for encrypt, private for decrypt",82 137,History,DH,"Diffie-Hellman key exchange (1976).","Agree on shared secret over insecure channel",68 138,XOR Cipher,Null Key,"XORing with 0 returns original.","x ^ 0 = x",94 139,XOR Cipher,Self Inverse,"XORing value with itself gives 0.","x ^ x = 0",94 140,Caesar Cipher,Negative Shift,"Shift of -3 is same as +23.","(-3 + 26) % 26 = 23",67 141,Caesar Cipher,Zero Shift,"No encryption if shift is 0.","Validate shift != 0",67 142,Vigenere,Autokey,"Self-keying variant using plaintext as key.","key = initial_key + plaintext",86 143,Vigenere,Running Key,"Use book text as very long key.","key = book_text",86 144,File I/O,Buffered vs Unbuffered,"setvbuf controls buffering.","setvbuf(fp, NULL, _IONBF, 0);",115 145,File I/O,Line Reading,"fgets reads one line.","fgets(line, sizeof(line), fp);",102 146,CLI,Subcommands,"Handle verb-style commands.","encrypt|decrypt|help",99 147,CLI,Verbose Mode,"Add -v for detailed output.","if(verbose) printf(""Processing...\\n"");",118 148,ASCII,Control Chars,"NUL SOH STX ETX etc.","Values 0-31",0 149,ASCII,Delete,"DEL is ASCII 127.","Non-printing control char",127 150,Test Patterns,Binary-like,"01001000 01100101 01101100","Space-separated binary",48 151,Memory,Reallocmaps,"Resize dynamic arrays.","buf = realloc(buf, new_size);",114 152,Errors,Timeout,"Handle slow operations.","Set alarm() for timeout",116 153,Best Practices,Logging,"Log operations for debugging.","fprintf(log_fp, ""..."");",108 154,Security,Obfuscation,"Not encryption - reversible without key.","ROT13, Base64 are not encryption",79 155,Makefile,Debug Build,"Add debug symbols.","debug: CFLAGS += -g -DDEBUG",100 156,History,Playfair,"Digraph substitution cipher.","Uses 5x5 grid",80 157,XOR Cipher,Properties,"Commutative and associative.","(A^B)^C = A^(B^C)",94 158,Caesar Cipher,ROT13,"Self-inverse: ROT13(ROT13(x)) = x.","shift = 13",82 159,Vigenere,Tableau,"26x26 table of shifted alphabets.","Vigenere square",86 160,File I/O,Error Checking,"ferror checks for errors.","if(ferror(fp)) {...}",102 161,CLI,Required Args,"Mark required arguments.","if(key == NULL) { error(); }",114 162,ASCII,Hex Values,"A = 0x41, a = 0x61, 0 = 0x30.","printf(""%02x "", c);",65 163,Test Patterns,Whitespace Only," ","Spaces and tabs only",32 164,Memory,Memory Leak,"Unreleased memory accumulates.","Use valgrind to detect",77 165,Errors,Stack Trace,"Use gdb for debugging.","gdb ./encrypt core",103 166,Best Practices,Assertions,"Check invariants with assert.","assert(key != NULL);",97 167,Security,Password Input,"Hide password during entry.","Use getpass() or termios",103 168,Makefile,Install Target,"Copy to system directory.","install: encrypt\\n\\tcp $< /usr/local/bin/",105 169,History,Book Cipher,"Key is page/line/word numbers.","Unbreakable if book unknown",66 170,XOR Cipher,XOR Linked List,"XOR can store prev and next in single pointer.","npx = prev ^ next;",94 171,Caesar Cipher,Affine,"Linear: E(x) = (ax + b) mod 26.","a must be coprime with 26",65 172,Vigenere,Beaufort,"Variant: E = K - P instead of K + P.","decrypt is same as encrypt",66 173,File I/O,File Locking,"Prevent concurrent access.","flock(fileno(fp), LOCK_EX);",102 174,CLI,Config Files,"Read settings from file.","parse_config("".encryptrc"");",99 175,ASCII,Newlines,"\\n = 10 (LF), \\r = 13 (CR).","Unix uses LF, Windows uses CRLF",10 176,Test Patterns,Very Long Line,"Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat","Long line for buffer testing",76 177,Memory,Memory Mapping,"mmap for large files.","void *data = mmap(NULL, size, ...);",109 178,Errors,Assertions,"Use assert for programming errors.","#include ",97 179,Best Practices,Const Correctness,"Mark read-only params as const.","void encrypt(const char *input);",99 180,Security,Secure Delete,"Overwrite before deleting.","shred -u filename",115 181,Makefile,Dependencies,"Track header dependencies.","main.o: main.c encryption.h",100 182,History,Navajo Code,"Unbreakable WWII voice cipher.","Language-based encryption",78 183,XOR Cipher,Visualization,"Binary XOR looks like addition without carry.","1010 ^ 0110 = 1100",94 184,Caesar Cipher,Decoder Ring,"Physical implementation.","Captain Midnight ring",68 185,Vigenere,Period,"Key length determines period.","period = len(key)",86 186,File I/O,feof vs return,"feof only true after failed read.","Check fread return first",102 187,CLI,Interactive Mode,"Prompt for missing arguments.","if(key==NULL) key = prompt_key();",105 188,ASCII,Bell,"BEL (0x07) makes terminal beep.","putchar(7);",7 189,Test Patterns,Zero Bytes,"\\0\\0\\0\\0\\0","Null bytes for binary testing",0 190,Memory,Alignment,"Aligned access is faster.","Use sizeof for array iteration",97 191,Errors,EINTR,"Handle interrupted syscalls.","while(read(...)==-1 && errno==EINTR);",69 192,Best Practices,Resource Cleanup,"Use goto for error cleanup.","goto cleanup;",103 193,Security,Code Review,"Review code for vulnerabilities.","Get peer review before release",67 194,Makefile,Quiet Mode,"Suppress command echo.","@$(CC) $(CFLAGS) -o $@ $^",64 195,History,Hill Cipher,"Matrix multiplication.","C = KP mod 26",72 196,XOR Cipher,Data Recovery,"XOR to recover corrupted data.","Use parity bits",94 197,Caesar Cipher,Variant,"Number cipher: A=0, B=1, etc.","Add shift to number",67 198,Vigenere,Quagmire,"Mixed alphabet variants.","4 different quagmire types",81 199,File I/O,Temporary Files,"Use mkstemp for secure temp files.","mkstemp(template);",116 200,CLI,Version Info,"Support --version flag.","printf(""%s version %s\\n"", PROG, VER);",118