Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Caesar Cracker:
- This program prints every possible Caesar Cipher
- for a given input. It's primary use case is in
- CTF or other "hacking" related competitions. Simply
- look through the output for real words.
- Written by Zachary Kline (www.ZachKline.us)
- September 11, 2019
- */
- #include <stdio.h>
- #include <ctype.h>
- void main(void) {
- char str[1024];
- int i, x;
- /* Accepts user input */
- printf("====================\nCaesar Cipher Cracker\nWritten by Zachary Kline\n====================\n");
- printf("Please enter a ciphered string (max 1024 characters): ");
- scanf("%[^\n]s", str); // The "[^\n] ensures that spaces are scanned in as well, so that you can paste in a whole sentence
- printf("\n");
- for (i = 1; i <= 26; ++i) {
- for (x = 0; str[x] != '\0'; ++x) {
- /*
- I had to make 2 separate if statements for
- whether the character was between a-z or A-Z
- so that we didn't accidentally start overflowing
- into numbers or symbols. This also had the added
- benefit of leaving numbers and symbols from the
- input untouched in the output.
- */
- if (str[x] >= 'a' && str[x] <= 'z') {
- str[x] = str[x] + 1;
- /*
- Next if statement corrects the output in
- case we accidentally fell outside of the
- alphabet by adding 1
- */
- if (str[x] > 'z') {
- str[x] = str[x] + 'a' - 'z' - 1;
- }
- }
- /*
- This next if statement is just a copy of
- the previous one, but for the capital alphabet
- */
- if (str[x] >= 'A' && str[x] <= 'Z') {
- str[x] = str[x] + 1;
- if (str[x] > 'Z') {
- str[x] = str[x] + 'A' - 'Z' - 1;
- }
- }
- }
- printf("+%d:\t%s\n", i, str);
- }
- }
Add Comment
Please, Sign In to add comment