C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
Loading...
Searching...
No Matches
caesar.h
Go to the documentation of this file.
1/**
2 * @file caesar.h
3 * @brief Caesar cipher encryption and decryption
4 *
5 * The Caesar cipher is one of the simplest encryption techniques.
6 * It works by shifting each letter by a fixed number of positions
7 * in the alphabet.
8 */
9
10#ifndef CAESAR_H
11#define CAESAR_H
12
13#include <stddef.h>
14
15/**
16 * @brief Encrypt a string using the Caesar cipher
17 *
18 * @param text The text to encrypt (modified in-place)
19 * @param shift The number of positions to shift (0-25)
20 *
21 * @note Only alphabetic characters are encrypted; others remain unchanged
22 * @note The shift is applied modulo 26
23 */
24void caesar_encrypt(char *text, int shift);
25
26/**
27 * @brief Decrypt a string encrypted with Caesar cipher
28 *
29 * @param text The text to decrypt (modified in-place)
30 * @param shift The shift value used for encryption
31 */
32void caesar_decrypt(char *text, int shift);
33
34/**
35 * @brief Encrypt a single character
36 *
37 * @param c The character to encrypt
38 * @param shift The shift value
39 * @return The encrypted character
40 */
41char caesar_encrypt_char(char c, int shift);
42
43/**
44 * @brief Decrypt a single character
45 *
46 * @param c The character to decrypt
47 * @param shift The shift value
48 * @return The decrypted character
49 */
50char caesar_decrypt_char(char c, int shift);
51
52/**
53 * @brief Crack a Caesar cipher by chi-squared comparison against English
54 * letter frequencies.
55 *
56 * For each candidate shift 0..25, the function "decrypts" with that shift
57 * and computes the chi-squared statistic between the resulting letter
58 * distribution and standard English. Lowest chi-squared = best shift.
59 *
60 * @param text The encrypted text to analyze
61 * @return The most likely shift value used (0–25)
62 */
63int caesar_crack(const char *text);
64
65#endif /* CAESAR_H */
char caesar_encrypt_char(char c, int shift)
Encrypt a single character.
Definition caesar.c:10
int caesar_crack(const char *text)
Crack a Caesar cipher by chi-squared comparison against English letter frequencies.
Definition caesar.c:38
char caesar_decrypt_char(char c, int shift)
Decrypt a single character.
Definition caesar.c:22
void caesar_decrypt(char *text, int shift)
Decrypt a string encrypted with Caesar cipher.
Definition caesar.c:36
void caesar_encrypt(char *text, int shift)
Encrypt a string using the Caesar cipher.
Definition caesar.c:27