|
C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
|
Caesar cipher encryption and decryption. More...
#include <stddef.h>Go to the source code of this file.
Functions | |
| int | caesar_crack (const char *text) |
| Crack a Caesar cipher by chi-squared comparison against English letter frequencies. | |
| void | caesar_decrypt (char *text, int shift) |
| Decrypt a string encrypted with Caesar cipher. | |
| char | caesar_decrypt_char (char c, int shift) |
| Decrypt a single character. | |
| void | caesar_encrypt (char *text, int shift) |
| Encrypt a string using the Caesar cipher. | |
| char | caesar_encrypt_char (char c, int shift) |
| Encrypt a single character. | |
Caesar cipher encryption and decryption.
The Caesar cipher is one of the simplest encryption techniques. It works by shifting each letter by a fixed number of positions in the alphabet.
Definition in file caesar.h.
| int caesar_crack | ( | const char * | text | ) |
Crack a Caesar cipher by chi-squared comparison against English letter frequencies.
For each candidate shift 0..25, the function "decrypts" with that shift and computes the chi-squared statistic between the resulting letter distribution and standard English. Lowest chi-squared = best shift.
| text | The encrypted text to analyze |
Definition at line 38 of file caesar.c.
Referenced by main().
| void caesar_decrypt | ( | char * | text, |
| int | shift | ||
| ) |
Decrypt a string encrypted with Caesar cipher.
| text | The text to decrypt (modified in-place) |
| shift | The shift value used for encryption |
Definition at line 36 of file caesar.c.
References caesar_encrypt().
Referenced by main().
| char caesar_decrypt_char | ( | char | c, |
| int | shift | ||
| ) |
Decrypt a single character.
| c | The character to decrypt |
| shift | The shift value |
Definition at line 22 of file caesar.c.
References caesar_encrypt_char().
| void caesar_encrypt | ( | char * | text, |
| int | shift | ||
| ) |
Encrypt a string using the Caesar cipher.
| text | The text to encrypt (modified in-place) |
| shift | The number of positions to shift (0-25) |
Definition at line 27 of file caesar.c.
References caesar_encrypt_char().
Referenced by caesar_decrypt(), and main().
| char caesar_encrypt_char | ( | char | c, |
| int | shift | ||
| ) |
Encrypt a single character.
| c | The character to encrypt |
| shift | The shift value |
Definition at line 10 of file caesar.c.
Referenced by caesar_decrypt_char(), and caesar_encrypt().